How to provoke PHP's built-in webserver to spit out its built-in "404 Not Found" webpage?

177 Views Asked by At

For security purposes, I fake this in one place in my code for certain requests:

http_response_code(404);
die();

This will return the correct (fake) "404 Not Found" HTTP status code, and show a blank page.

I could of course replicate/fake the error page as well, for example by simply copying it, storing it separately and then echoing it before/with the die() call. However, this I consider "ugly", and will tie my code to specifically the built-in PHP webserver, and possibly make it differ after some time, if the PHP developers change it in the future. It's just not a good solution.

I want this to be completely independent on the webserver and everything. I want to provoke the webserver to send its genuine default "404 Not Found" webpage, no matter what it looks like. And I don't want it to reveal that it's not the right error page, for example by saying:

Could not find "dummydummydummydummy.php?blablabla=123" on this server.

That is, the solution must not consist of "internally faking" the request URI or anything like that.

I want it to appear as if the request truly is not valid, even though the page technically exists.

From PHP. Not some webserver-dependent configuration. (I got quite enough of that after 20 years of the Apache HTTP Server's manual.)

0

There are 0 best solutions below