Log in

View Full Version : Getting requested URL in custom error pages



Blake
03-10-2007, 04:04 PM
I'm making custom error pages for my website. I would like the 404 error page to say something along the lines of

Error 404: Requested URL [filename] not found on server.

where [filename] is the name of the file/directory requested. The problem I'm having involved actually getting that file name. I've tried the following:



<h1>Error 404</h1><br>Requested URL <?php echo $_SERVER['REQUEST_URI']; ?> not found on server.


However, instead of giving me the requested page, $_SERVER['REQUEST_URI'] gives me the url of the error page.

How would I get the URL of the requested page instead of the url of the error page?

thetestingsite
03-11-2007, 05:26 AM
You should be able to use $_SERVER['REQUEST_URI'] or $_SERVER['HTTP_REFERER'] (< spelling?). Although, not 100&#37; sure without testing it.

Hope this helps though.

tech_support
03-11-2007, 05:34 AM
It's
$_SERVER['HTTP_REFERER']

Twey
03-11-2007, 11:41 AM
$_SERVER['HTTP_REFERER'] (< spelling?)Wrong, but the header's spelt incorrectly too, so you're right :) The word is usually "referrer."

However, this shouldn't be the case. Referer should, in this case, be the URL to the page with the dead link. You really want $_SERVER['REQUEST_URI'].