Jump to content

[SOLVED] 404 error on incorrect php parameter ... possible?


atomicrabbit

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.