Jump to content

[SOLVED] how do I redirect a page back to a dynamic url?


poleposters

Recommended Posts

Hi,

 

Can anyone let me know  if this is  possible?

 

My site displays several pages of listings. But on the right hand side of the page I have a newsletter signup form. If someone decides to signup while theyre browsing, I want them to return automatically to the page they were viewing.

 

For example after the newsletter script runs I'd like them to return to the URL

 

http://localhost/searchcat.php?catid=1&searchterm=2000&start=10 which is the second page of results with the category id '1' and the search term '2000'.

 

Any clues?

 

Cheers

There are two options:

 

1) On the script the form submits to, use the value of $_SERVER['HTTP_REFERER']

<?php
  $referer = isset($_SERVER['HTTP_REFERER'])
    ? $_SERVER['HTTP_REFERER']
    : 'index.php'; //Default value in case there is no referer
  header('Location: '.$referer);
  exit;
?>

 

 

2) In the form, have a hidden field called referer, and set the value of it to $_SERVER['REQUEST_URI']

<form method="post" action="subscribe.php">
  <input type="hidden" name="referer" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
  Email: <input type="text" name="email" />
  <input type="submit" value="Submit"
</form>

<?php
  $referer = isset($_POST['referer'])
    ? $_POST['referer']
    : 'index.php'; //Default value in case there is no referer
  header('Location: '.$referer);
  exit;
?>

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.