I wouldn't rely on HTTP_REFERER at all.. some user agents don't set it.

For things that need to revert back to a certain URL after a few tasks have
been performed (eg login, email page to a friend, add to cart, add to
wishlist, etc etc).

To do this, I use PHP_SELF ($_SERVER['PHP_SELF'] in PHP >= 4.1 I believe),
along with any current query string ($_GET), to establish a $ref var which
is essentially a URL that represents the page in it's current state, eg:


I base64() encode it (so that it can be carried around in URLs without
messing up other GET variables on subsequent pages), and then it's ready to
ship around.

Basically, if someone wants to login, they click on my login link which
looks like:

<A HREF="login.php?ref=<?=$ref?>">login</a>

login.php looks for, and carries around the $ref variable untill the login
process in complete (could be a few "pages", due to errors, etc), then once
the user is logged in successfully, uses header("Location: $ref") to send
the user back to where they were.

So, in short, before going to your "add to cart" script, make note of your
state (where you are -- script name and query string), carry this around as
a var in the URL until you're ready to go back to that page and continue.

I do this on every site, but with more features (I've basically got a
"stack" of things that need to be done).

Good luck!

Justin French

on 08/07/02 7:30 PM, Wilbert Enserink ([EMAIL PROTECTED]) wrote:

> Hi all,
> What's the best way to implement functions like 'add to basket' or 'add to
> wishlist' and so on.
> I mean: you are on a page with detail information about a product. If the user
> clicks the link for 'add to basket' I have to perform a piece of script and
> then go back to the detail page of the given product. But clicking on this
> link leads me away form the page...
> I was thinking of using $HTTP_REFERER i the "ad_to_basket.php" page in order
> to retrieve the last url, but now I don't know how to go back to this
> detailpage, is there a php command for this, or is my approach totally wrong??
> Any comments would be appreciated,
> regards. 
> Wilbert Enserink
> -------------------------
> Pas de Deux
> Van Mierisstraat 25
> 2526 NM Den Haag
> tel 070 4450855
> fax 070 4450852
> http://www.pdd.nl
> -------------------------

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to