I printed $_SERVER, and I found out that $_SERVER['REDIRECT_URL']
vs $_SERVER['REQUEST_URI']
both have same values. What's the difference between the two?
$_SERVER['REQUEST_URI'] contains the URI of the current page. So if the full path of a page is https://www.w3resource.com/html/html-tutorials.php, $_SERVER['REQUEST_URI'] would contain /html/html-tutorials. php.
In cases where you do need it, the answer is that yes, REQUEST_URI is safe.
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.
$_SERVER['PHP_SELF'] Returns the filename of the currently executing script.
REQUEST_URI is the requested URI path and query as used in the HTTP request line. REDIRECT_URL is created by Apache when an internal redirect happens:
REDIRECT_
environment variables are created from the environment variables which existed prior to the redirect. They are renamed with aREDIRECT_
prefix, i.e.,HTTP_USER_AGENT
becomesREDIRECT_HTTP_USER_AGENT
.
REDIRECT_URL
,REDIRECT_STATUS
, andREDIRECT_QUERY_STRING
are guaranteed to be set, and the other headers will be set only if they existed prior to the error condition.
Note that REDIRECT_URL does only contain the URI path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With