Posted by & filed under PHP.

$_SERVER['HTTP_REFERER'] gives you the URL from where the user came, which is the user’s previous page (whatever page that would appear if the user clicked “Back” in their browser)

But $_SERVER['HTTP_REFERER']  gives you the complete URL, something like this :

If you just want get the domain name .i.e. from the full URL, then you can use the following code:

$referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);

Note though that the referer is easy to spoof, so it’s not reliable.