I want the the url of the page from which a request has been made. How can I do that in PHP?
Asked
Active
Viewed 3.0k times
2 Answers
28
The refer(r)er can be found in the $_SERVER
global variable. Please note that sending the refer(r)er is completely optional and a user-agent can simply decide to not send the refer(r)ing url.
$_SERVER['HTTP_REFERER']

Stefan Gehrig
- 82,642
- 24
- 155
- 189
-
I have two questions: 1- It is optional, OK, but does it possible changed by the user agent. i.e foobar.com, the user agent could send it as barfoo.net?! 2- Does web crawler's such as Google-Bot, regarded as user agent? – SaidbakR Aug 24 '14 at 12:24
-
1The referrer can be changed by the browser, by a browser plugin, by some network component (proxy) or by some malware code for example. And yes, most bots identify themselves using the user-agent string. – Stefan Gehrig Aug 24 '14 at 16:11
9