views:

645

answers:

4

I am using $_SERVER['HTTP_REFERER']; to get the referer Url. It works as expected until the user clicks another page and the referer changes to the last page.

How do I store the original referring Url?

+4  A: 

Store it either in a cookie (if it's acceptable for your situation), or in a session variable.

<?php

  session_start();

  if (!isset($_SESSION["origURL"]))
    $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"];

?>
Jonathan Sampson
Thanks everyone, much much appreciated! Jonathan got their first.
Keith Donegan
+1  A: 

Store it in a cookie that only lasts for the current browsing session

Matt
+2  A: 

As Johnathan Suggested, you would either want to save it in a cookie or a session.

The easier way would be to use a Session variable.

session_start();
if(!isset($_SESSION['org_referer']))
{
    $_SESSION['org_referer'] = $_SERVER['HTTP_REFERER'];
}

Put that at the top of the page, and you will always be able to access the first referer that the site visitor was directed by.

Chacha102
+1 - Great minds think alike ;)
Jonathan Sampson
+1  A: 

And don't forget to escape $_SERVER["HTTP _REFERER"] since its a common attack vector for web apps .

pcp