Search code examples
phpnavigationbreadcrumbshttp-referer

Pass original http_referer to other pages


I have a business profile set up with a separate gallery page. The header for these pages is a php include.

I am trying to set up a breadcrumb trail for this profile so am using http_referer to track which listings page I came from.

if ($title == 'Business Profile'){
session_start();
$referer = $_SERVER['HTTP_REFERER'];
}
?>

The problem I have is passing the http_referer as a variable from the business profile to the gallery page. How would I do this so that I can link back to the listings page from both the business profile and the gallery? If I use http_referer on the gallery page it will only take me back to the profile I came from.


Solution

  • You could use cookies? For example on your landing page;

    if(!isset($_COOKIE['HTTP_REFERER']))
    {
        $expiryTime = time()+(60*60*24); // Set to expire after 1 day
        setcookie('HTTP_REFERER',$_SERVER['HTTP_REFERER'],$expiryTime,'/');
    }
    

    And then on all other pages you can detect if there is a cookie already set;

    if(isset($_COOKIE['HTTP_REFERER']))
    {
        $referer = $_COOKIE['HTTP_REFERER'];
    }