Page 1 of 1

Browser back button functionality

Posted: Sat Jul 24, 2004 3:13 am
by kumar_manoj77
i have three php pages page1, page2, page3
page1 has link to page2
page2 has some link which call page2 itself
when usr visit page1 and click on link for page2
on page2 user click on link which call itself again
now if user click on brwoser's back button the page displayed is again page2. but i want the page displayed should be page1 rather than page2
how can i get this
for example u can see this link
http://www.netphonecards.net/innovatve/phone_cards.php
click on buy now link
the page opend is shop_cart.php
click on add one more link in Action coloumn of table
when i click on browser' back button it remain on same page
but i need the following functionality as this url
http://www.247smart.com/cards/
please help to get this functionality

Posted: Sat Jul 24, 2004 3:25 am
by feyd
the only way I remember being able to do something like this is through telling the Javascript history object to replace this page with some other page. However, with many people having javascript off these days, I wouldn't bank on being able to do it too easily.

With some creative fiddling, you could use sessions to figure out which direction(s) they are moving and switch out the content based on that direction..

Posted: Sat Jul 24, 2004 4:23 am
by JAM
Pseudo code fopr ideas, based on feyd's thoughts as I wanted to mention the use of REQUEST_URI also.

Code: Select all

// page1.php
$_SESSION['visited'] = 0; // set a session for temporarily use
User presses "next" on page1, and goes to page2...

Code: Select all

// page2.php

if ($_SERVER['REQUEST_URI'] == 'page2.php' and $_SESSION['visited'] == 0) {
    $_SESSION['visited'] = 1;
    // do whatever you want.
} else {
    // allready visited this page once...
      header('Location: page1.php');
}
Or something similiar... Perhaps I gave away to much info here... Ah well...