Page 1 of 1

How to go back 2 pages

Posted: Wed Nov 15, 2006 10:25 pm
by jdhorton77
Ok, I've got a page that allows the user to enter his information, username and password. And after a successfull insertion to a data base I would like to be able to go back 2 pages. I was wondering if PHP had a function to do this. I know JavaScript has history.back and I tried to use it through an echo statement like such:

Code: Select all

echo '<script language="JavaScript" type="text/javascript">history.back(2)</script>';
but it doesn't seem to work.

Thanks for your help.

Posted: Wed Nov 15, 2006 10:41 pm
by feyd
PHP does not have functionality to go back two pages.

You may want to instead provide a link (forward) to whatever page that may be.

Use header()

Posted: Wed Nov 15, 2006 11:01 pm
by zeek
If you can pass the url of the [page 2 pages ago] to your script via a cookie or query string value, you can redirect the browser to that address like this:

Code: Select all

header( 'Location: ' . $url );
exit;

Posted: Thu Nov 16, 2006 4:40 pm
by jdhorton77
Cool, I thought about just using an if statement and then echoing different form actions. But the header might be easier.

Posted: Thu Nov 16, 2006 6:20 pm
by Cameri
Did you try?

Code: Select all

history.go(-2);