Question

Can someone tell me that:

Can we get two step back referrer using php ? for example someone come though google.com to mysite.com and then he/she clicked on any other page of like mysite.com/page.php and on that page referrer should be google.com not mysite.com

possible ? Pleas help

Was it helpful?

Solution

You can save it to cookie or session and use it on the next page.

if (!isset($_SESSION)) {
    session_start();
}
if (!isset($_SESSION['referrer'])) {
    $_SESSION['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'n/a';
}

// another page

$referer = isset($_SESSION['referrer']) ? $_SESSION['referrer'] : null;

OTHER TIPS

The variable

$_SERVER['HTTP_REFERER']

CAN contain the referer, but it can only go one level deep, so you can see where the visitor came from, one step back, but not two steps.

use $_SERVER['HTTP_REFERER'] will get referrer if exists

I was looking to do the same thing a couple years ago. It is impossible to achieve it. If it is otherwise, i would be interested to know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top