简体   繁体   中英

Change urls depending on landing page

I have two landing pages (homepage1 and homepage2). If I land on homepage1, the logo link needs to change to homepage1 and keep it as I go to other pages. The same goes when I land on homepage2. I tried -

if (strstr($_SERVER['HTTP_REFERER'], 'homepage1.php') !== false) { 
    <a href='homepage1.php'><img src='logo.jpg'></a>
}

elseif (strstr($_SERVER['HTTP_REFERER'], 'homepage2.php') !== false ) { 
    <a href='homepage2.php'><img src='logo.jpg'></a>
} 

It works when I go to one page but anymore than one the url and logo are gone. In other words, it doesn't hold on to the url.

I need it to hold on to the url based on what landing page I land on. And it needs to hold on to the url, no matter how many pages I go to.

Is this possible?

As @DragonYen pointed out , you need to use session variable as it can be used to persist state information between page requests.

session_start();

$ref = $_SERVER['HTTP_REFERER'];
$page = explode("/", $ref); 

if($page[3] == "homepage1.php") { 
    $_SESSION['home'] = 1;
}

else if($page[3] == "homepage2.php")  {     
    $_SESSION['home'] = 2;
}  

Now you can check for session variable home

 if ($_SESSION['home'] == 1) { 
    <a href='homepage1.php'><img src='logo.jpg'></a>
}

elseif ($_SESSION['home'] == 2) { 
    <a href='homepage2.php'><img src='logo.jpg'></a>
} 

put this when you no longer need the session

unset($_SESSION['home'];
session_destroy();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM