Custom 404 page + returning incorrect URL

I have a custom 404 page declared via .htaccess on an Apache server.

My question: Is there a way with PHP to grab an incorrectly-entered URL?

I wish to somehow grab the incorrect URL typed in that accessed the 404.php in the first place and assign it to a $var for use in an e-mail.

Using magic constants like FILE or extracting the current script name via $_SERVER[‘SCRIPT_NAME’] obviously returns 404.php since it the valid file name name executing the script.

Thanks :smiley:

I don’t know where $_ENV gets it’s data from but AFAIK $_SERVER gets its data from the server on which php is running. It does seem strange that there is $_SERVER and $_ENV that duplicate each other, my guess is that there is some difference behind the scenes as to how they get the information.

What about $_SERVER[‘REQUEST_URI’] ?

The URI which was given in order to access this page; for instance, ‘/index.html’.

$_ENV gets it’s information from the “environment” (you know, the space where PATH and stuff are also set).
It’s less certain to rely on $_ENV (some servers I worked have an empty array for $_ENV !) whereas $_SERVER has never been a problem for me.

TL;DR Use $_SERVER

I’ll just stick with $_SERVER just to be safe.

Everything is working great so thanks a bunch for the help! :smiley:

Yup, that worked. The $_ENV version works as well - does it matter which one I use? Both are superglobals are they not?