garysenter Posted May 18, 2006 Share Posted May 18, 2006 is there a way to direct the users back to a previous page automatically. right now i use the header("Location: ......"); to direct them, but what I want is for them to go to the second to last page they were at before they got to this page. I tried [code]<script LANGUAGE="JavaScript" type="text/javascript"> <!-- history.back(); //--></SCRIPT>[/code]But that only took me back to the very last page I was at. I want to go back 2 pages.Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/9938-go-to-the-previous-page/ Share on other sites More sharing options...
ober Posted May 18, 2006 Share Posted May 18, 2006 There is no function in PHP that will allow you to go back twice. The only way to do that would be to store a history in a cookie or in a session and then pull that out and stick it in header(Location:...) Quote Link to comment https://forums.phpfreaks.com/topic/9938-go-to-the-previous-page/#findComment-36929 Share on other sites More sharing options...
janggu Posted May 18, 2006 Share Posted May 18, 2006 Or, you can do it this way.[code]Do somethingif (something happened)echo "<meta http-equiv='refresh' content='1; url=your2ndpage.php' />";die "<p align='center'>Thanks! Redirecting...</p>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9938-go-to-the-previous-page/#findComment-36933 Share on other sites More sharing options...
ober Posted May 18, 2006 Share Posted May 18, 2006 That only works if that 2nd page is pre-defined... your solution fails if you plan to put this in place throughout a website. Quote Link to comment https://forums.phpfreaks.com/topic/9938-go-to-the-previous-page/#findComment-36937 Share on other sites More sharing options...
garysenter Posted May 18, 2006 Author Share Posted May 18, 2006 i figured it out. I created a variable and gave it the data from $refpage = $_SERVER['HTTP_REFERER'];. Then on the other page i used that in the header("location: $refpage"); and it works. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/9938-go-to-the-previous-page/#findComment-36948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.