Hello I'm looking for a way to have a referer when I'm using a redirection. Let me explain. I have a page on domain1 which send the visitor to the domain2. I use a header redirection. But on domain2, I want to know if the visitor is coming by this redirection. Everytime I checked the referer, it's blank... Who can tell me how to redirect a visitor and identify it after ? Thanks a lot
Hello My code in domain1 is : header("Status: 301 Moved Permanently", false, 301); header("Location: domain2"); exit(); I also try : header("Refresh: 0;url=domain2"); exit(); And the code on the second domain : $url =$_SERVER['HTTP_REFERER']; echo $url;
What he is saying that you do something like: header("location: domain.com/?utm_source=domain1"); Code (markup): Then on your domain 2 do: $referrer = isset($_GET['utm_source']) ? $_GET['utm_source'] : 'no referrer'; echo $referrer; Code (markup):
This snippet might get you in right direction: <?php $rdom = "http://domain.com/"; //Domain1 $ref = $_SERVER['HTTP_REFERER']; //Get Referrer //Check if user coming from domain1 if ($ref == $rdom) { echo "Correct"; //Correct Referrer } else { echo "Wrong"; //Wrong Referrer } ?> PHP:
You might find this helpful too : HTTP_REFERER is an environment variable sent by the browser. Some browsers give the user the option to remove it when making a http request.
Hello Thx to all of you. Unfortunatly, the redirection broke the referer so HTTP_REFERER is useless. But I used the technique with a special page and it's fine ! So THANKS FOR YOUR HELP
Why not check if referer is external and then save it to a session? something like this if ($_SERVER['HTTP_REFERER'], 0, strlen($yourUrl)) != $yourUrl) { // ofcource session_start() must be started! $_SESSION['ref'] = $_SERVER['HTTP_REFERER']; } // do your header thing PHP: