finding referrer to current page/script [duplicate]
Possible Duplicate:
php/html - http_referer
I w开发者_高级运维ant to find which page/script get request to current page/script.
For example
I am on page "index.php"
I click on link that takes me to "about.php"
Now, on "about.php", I need to find referrer, i.e., "index.php"
I need solution, that works on any OS/Platform (Windows, Linux, Mac OS X)
Thank
Don't trust $_SERVER['HTTP_REFERER']
: it is a bad solution because it's not reliable, set by the user agent, possible to modify, and not always set or is set incorrectly.
Try setting the current page to a $_SESSION
item at the end of each page load, and referencing that as your "last url". It will work as long as the last url was within your site, otherwise the $_SERVER['HTTP_REFERER']
is probably your only way.
However, DO NOT trust it, and whatever you do, don't redirect to it within your site or you may find yourself in an infinite redirect loop.
You can use:
$_SERVER['HTTP_REFERER']
精彩评论