How to go back 2 pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

How to go back 2 pages

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

Use header()

Post 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;
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Post by jdhorton77 »

Cool, I thought about just using an if statement and then echoing different form actions. But the header might be easier.
User avatar
Cameri
Forum Commoner
Posts: 87
Joined: Tue Apr 12, 2005 4:12 pm
Location: Santo Domingo, Dominican Republic

Post by Cameri »

Did you try?

Code: Select all

history.go(-2);
Post Reply