Jump to content

Archived

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

garysenter

go to the previous page

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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:...)

Share this post


Link to post
Share on other sites
Or, you can do it this way.


[code]
Do something

if (something happened)
echo "<meta http-equiv='refresh' content='1; url=your2ndpage.php' />";
die "<p align='center'>Thanks! Redirecting...</p>";[/code]

Share this post


Link to post
Share on other sites
That only works if that 2nd page is pre-defined... your solution fails if you plan to put this in place throughout a website.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.