Forum Moderators: coopster

Message Too Old, No Replies

set page URL session

         

abanana

10:00 pm on Jul 31, 2006 (gmt 0)

10+ Year Member



hi all,

please would you tell me how to set session on page URL?

all i want to do is when click on a link(say "Continue Shopping"), it will go back to the last viewed search result page (for customers continue add items to their shopping cart).

is it possible?

thanks very much

abanana

9:33 am on Aug 1, 2006 (gmt 0)

10+ Year Member



anybody there please?!

coopster

11:36 am on Aug 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, abanana.

There are a number of ways to store and/or retrieve the last visited page during a session. One way is to check the HTTP_REFERER, but that is not reliable. You are probably better off storing the page they are on in your session.

FalseDawn

5:57 pm on Aug 1, 2006 (gmt 0)

10+ Year Member



Several sites use what is known as a "breadcrumb", with the last 2 or 3 pages visited being displayed as links somewhere near the top of the screen.
These pages are invariably stored in an array in the session (with the session propagating as usual - either by a cookie or a SID in the URL).
To return to the "previous" page is generally then just a matter of retrieving the appropriate URL from this array and redirecting.

I know osCommerce has a breadcrumb implemented like this - you might want to look at the code for ideas.
Of course, a simple javascript redirect like history.go(-1) would work in a javascript-enabled browser.

[edited by: FalseDawn at 5:57 pm (utc) on Aug. 1, 2006]

FiRe

10:07 am on Aug 2, 2006 (gmt 0)

10+ Year Member



Stick this code on the search pages at the top:
<?php
session_start();
$_SESSION['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];

// Rest of the PHP code goes here


Now when you get to the Continue Shopping page you would do this:
<?php
session_start();

// PHP code goes here
// Now here is the 'Continue Shopping' link

echo '<a href="'.$_SESSION['url'].'">Continue Shopping</a>';

[edited by: FiRe at 10:07 am (utc) on Aug. 2, 2006]

abanana

6:17 am on Aug 3, 2006 (gmt 0)

10+ Year Member



thanks very much for your replies!

i tried the code FiRe mentioned, but when i click, it ask me search again. Say if i click "Add to cart" on this page:
"http://localhost/search.php?page=4&searchterm=book"

the actual link of "continue shopping" will turn out to be
"localhost/search.php"

looks like it's very difficult to back a specific page!