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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.