Browser back button functionality

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
kumar_manoj77
Forum Newbie
Posts: 1
Joined: Sat Jul 24, 2004 3:13 am

Browser back button functionality

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

Post 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..
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
Post Reply