Jump to content

conditional header redirect?


turpentyne

Recommended Posts

is it possible to have a script that changes header based on what page the user came from.

 

something like

 

if ($_SERVER['HTTP_REFERER']) == http://www.site.com/pagebefore.php) { // do nothing, letting page generate }
else { header("Location: back_to_the_start_buddy.php"); }

 

 

Link to comment
https://forums.phpfreaks.com/topic/259594-conditional-header-redirect/
Share on other sites

The only thing I would change is the way you did it, but your code is right, more like this

 

if ($_SERVER['HTTP_REFERER']) != 'http://www.site.com/pagebefore.php') {
  header("Location: back_to_the_start_buddy.php");
  exit;
}

// continue to process page

dang! Not that easy after all. It redirects if I try to just load the page, but if I hit the back button, it'll load the page again. I don't want that.

 

I'm using session to pass info and do have each page caching for 7 minutes, I took that out on the page in question, no difference. It just gives me the warning about reloading the page.

You could set a page session and change the session to be page specific for each page, then check for it on each step.

 

On firstpage

$_SESSION['page'] = 2;

 

Second page

if ($_SESSION['page'] != 2) {  
  header("Location: firstpage.php"); 
  exit;
}
$_SESSION['page'] = 3;

 

Third page

if ($_SESSION['page'] != 3) {  
  header("Location: firstpage.php"); 
  exit;
}
$_SESSION['page'] = 4;

 

Last page

if ($_SESSION['page'] != 4) {  
  header("Location: firstpage.php"); 
  exit;
}
unset($_SESSION['page']);

 

If they hit back, it will redirect to the firstpage

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.