CJ - Twitch Posted May 30, 2010 Posted May 30, 2010 Is there a function that redirects a user to an error page if they are on a page that in not included or required? If not is there a way to do this? Many thanks. CJ Quote
Zero-Affect Posted May 30, 2010 Posted May 30, 2010 if (!empty($error_msg)) { header('Location: /error_page.php?msg=1'); } in your footer or something? <?php $error_msg = array( 1 => 'error one', 2 => 'error two' ); $_GET['msg'] = (isset($_GET['msg']) && array_key_exists($_GET['msg'], $error_msg)) ? $_GET['msg'] : 1 ; echo ' <h1>Error!</h1> '.$error_msg[$_GET['msg']]; ?> in error_msg.php Quote
Dave Posted May 30, 2010 Posted May 30, 2010 You need to use .htaccess my friend :) Google .htaccess error pages. Quote
Zero-Affect Posted May 30, 2010 Posted May 30, 2010 wouldn't that be for 404 and so on though Dave, NOTE i edited my previous post should work but untested. Quote
iSOS Posted May 30, 2010 Posted May 30, 2010 Just add this into .htaccess. ErrorDocument 404 /ErrorPage.html I don't fully understand what you want as your post doesn't make sence but If I'm thinking along the right lines it'll work, any time a user goes to a that file that doesnt exist it will re-direct them... Quote
CJ - Twitch Posted May 30, 2010 Author Posted May 30, 2010 I don't think you Understand. ^^ What I would like is if a user is on a page e.g header.php directly it sends them to a error page. If there on a page than includes header.php they stay on the page.. Quote
Zeggy Posted May 30, 2010 Posted May 30, 2010 On the file that you include header.php, above the include add this: define('IN_GAME', true); On top of header.php, add this: if (!defined('IN_GAME')) { header('Location: error.php'); exit; } Quote
CJ - Twitch Posted May 31, 2010 Author Posted May 31, 2010 Thanks. Works perfectly. .. *Goes to edit every file...* Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.