1

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

1
  • If you want to track the user's path to and through your site, append the current referer to a list of URLs in the session with each request. If you want to know about anything past the link that led to you, though, you're kinda screwed. Commented May 16, 2013 at 14:28

4 Answers 4

4

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;
Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

Maxim Khan-Magomedov's code working perfectly for 2 step back referrer :)
Only if they are on your own pages, not if they are coming from another page.
1

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

4 Comments

I think the question is how to pass referrer to the next step, when you click link inside your site.
I want 2 step back referrer.. not current page referrer
Yes Maxim Khan you are right I want to know how to pass referrer to next page/step ?
If you would be able to do this, you would be able to find out someone's whole browsing history... I think there would be a privacy issue there...
1

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.

2 Comments

Maxim Khan-Magomedov's code working perfectly for 2 step back referrer :)
@borniet is correct. It only works if it is your own pages. If that is what you are looking for, then great :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.