Get HTTP Referrer on Redirection
Asked Answered
U

2

8

How can you get the HTTP Referrer when redirected from another website, not when they click on a link since it would work for $_SERVER['HTTP_REFERER'], but it doesn't work when a user has been redirected a website and the referrer would be empty.

What will be the method to get the referrer?

Unteach answered 28/10, 2010 at 13:7 Comment(0)
W
9

How can you get the HTTP Referrer when redirected from another website

You can't. If the redirection takes place under your control, you can add the original referer as a parameter, but if the external redirector doesn't do that, you have no way to get hold of the information.

Widespread answered 28/10, 2010 at 13:11 Comment(3)
Aw. So there is absolutely no way to know where the user came from when the user got redirected?Unteach
@YouBook not as far as I know, no.Widespread
Javascript redirects send HTTP Referer header. See here for a more detailed description and use case: https://mcmap.net/q/216770/-will-a-302-redirect-maintain-the-referer-stringDocker
R
4

An example of how I did it. Say we have 3 pages, one calling the next.

page1.com -> page2.com -> page3.com.

in page2.com get the page1.com using:

$referrer = $_SERVER['HTTP_REFERER'];//=page1.com

when redirecting to page3, send $referrer as a GET parameter

page3.com?referrer=$referrer

in page3 read the $referrer from the get.

$initialReferrer = $_GET['referrer'];//=page1.com
Ressieressler answered 1/8, 2013 at 13:44 Comment(1)
One could directly call a page3.com?referrer=page4.com so take care about security/allowance issues. Plus, $_SERVER['HTTP_REFERER'] must be rawurlencode`-d before being appended to the URL.Zionism

© 2022 - 2024 — McMap. All rights reserved.