atomicrabbit Posted March 8, 2009 Share Posted March 8, 2009 Ok so .. as basic as I can put it, I have an index.php page that accepts a value for the parameter "p". So index.php?p=whatever Is it possible to have it go to a 404 error page if the "whatever" is not found? Currently, I'm using a php switch, so... $page = $_GET['p']; switch ($page) { case "one": //do something break; case "two": //do something break; case "three": //do something break; default: header("HTTP/1.1 404 Not Found"); header("Location: 404.php"); break; // continue some code But that code just redirects to the 404 page and it changes the URL in the address bar and the $_SERVER['REQUEST_URI'] is changed to the 404.php page, instead of the page that was requested. Whereas if the URL that was entered was hxxp://www.domain.com/page-that-doesnt-exist.html, the URL in the address bar would not change and still go to the error doc that is defined in the .htaccess file and the $_SERVER['REQUEST_URI'] would be "/page-that-doesnt-exist.html" Basically: Is there a way to tell the server that the page doesn't exist if a php page's parameter is incorrect, without redirecting using a header("Location: ...") call? Link to comment https://forums.phpfreaks.com/topic/148443-solved-404-error-on-incorrect-php-parameter-possible/ Share on other sites More sharing options...
WolfRage Posted March 8, 2009 Share Posted March 8, 2009 <?php echo '<meta http-equiv="refresh" content=.01; url='.$location.'" />'; ?> Link to comment https://forums.phpfreaks.com/topic/148443-solved-404-error-on-incorrect-php-parameter-possible/#findComment-779334 Share on other sites More sharing options...
corbin Posted March 8, 2009 Share Posted March 8, 2009 If you know the path to the 404 page, you could just readfile() it or include it. Link to comment https://forums.phpfreaks.com/topic/148443-solved-404-error-on-incorrect-php-parameter-possible/#findComment-779337 Share on other sites More sharing options...
atomicrabbit Posted March 8, 2009 Author Share Posted March 8, 2009 If you know the path to the 404 page you could just ... include it. Ahhhhhhhhhhhhh i see the light now... why didn't I think of that... thanks corbin! Link to comment https://forums.phpfreaks.com/topic/148443-solved-404-error-on-incorrect-php-parameter-possible/#findComment-779349 Share on other sites More sharing options...
corbin Posted March 8, 2009 Share Posted March 8, 2009 ;p Link to comment https://forums.phpfreaks.com/topic/148443-solved-404-error-on-incorrect-php-parameter-possible/#findComment-779352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.