Question

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.

Was it helpful?

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'];
}

OTHER TIPS

1) I you should check if referer address is not from my server.

2) If not, you can save this to session or cookie.

3) Finally you can use it as you wish;

<?php
session_start();
if(strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])===FALSE){
    $_SESSION['refererPage']= $_SERVER['HTTP_REFERER'];
    // or set cookie by Stu
}
?>

Use eg.

<?php
if(!empty($_SESSION['refererPage']))
    echo '<a href="'.$_SESSION['refererPage'].'">Back</a>';
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top