poleposters Posted April 7, 2008 Share Posted April 7, 2008 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 Link to comment https://forums.phpfreaks.com/topic/99998-solved-how-do-i-redirect-a-page-back-to-a-dynamic-url/ Share on other sites More sharing options...
rhodesa Posted April 7, 2008 Share Posted April 7, 2008 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; ?> Link to comment https://forums.phpfreaks.com/topic/99998-solved-how-do-i-redirect-a-page-back-to-a-dynamic-url/#findComment-511368 Share on other sites More sharing options...
poleposters Posted April 7, 2008 Author Share Posted April 7, 2008 Fantastic. Thanks heaps! Link to comment https://forums.phpfreaks.com/topic/99998-solved-how-do-i-redirect-a-page-back-to-a-dynamic-url/#findComment-511385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.