Jump to content


Photo

go to the previous page


  • Please log in to reply
4 replies to this topic

#1 garysenter

garysenter
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 May 2006 - 05:14 PM

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
<script LANGUAGE="JavaScript" type="text/javascript">
    <!--
    history.back();
    //-->
</SCRIPT>
But that only took me back to the very last page I was at. I want to go back 2 pages.

Any ideas?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 18 May 2006 - 05:20 PM

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:...)

Info: PHP Manual


#3 janggu

janggu
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 18 May 2006 - 05:28 PM

Or, you can do it this way.


Do something

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


#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 18 May 2006 - 05:31 PM

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

Info: PHP Manual


#5 garysenter

garysenter
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 May 2006 - 05:50 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users