Retrieving Historic URLs

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
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Retrieving Historic URLs

Post by Crashin »

This topic might do better in the "Theory and Design" forum, but it's code related, too. At any rate...

I've got a situation where I'm implementing a 3rd party shopping cart to process transactions, but I'm using static pages (for now) to display our product catalog to our customers. I've been able to modify the shopping cart code so that, when a user adds a product from our site to their cart, the "Continue Shopping" button will return them to the product page from which they came (ala $_SERVER['HTTP_REFERER']).

The problem arises when the user views to their shopping cart from a product page and then makes changes to their cart, such as removing or changing the quantity of an item. Because the shopping cart page uses itself to process the change, $_SERVER['HTTP_REFERER'] becomes the shopping cart page, not the product page from which they came. Thus, the "Continue Shopping" button takes them back to their shopping cart.

I could instead check the value of $_SERVER['HTTP_REFERER'] and determine if it is the shopping cart and, if so, just send them to the product catalog index. But, that's not the page from which they came. I'd much rather send them back to the product page from which the came to the shopping cart.

Any thoughts??? :?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

My thoughts are you should not be coding a shopping cart if you cannot figure out this problem.

[moderatorial=Weirdan]
Could you please try to be somewhat helpful? If not you'd better not to post at all.
[+] Moderatorial warning.
[/moderatorial]
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Thanks for the tip, and don't worry about it.

Anyway, my question still stands.
ipb1024-ipb
Forum Newbie
Posts: 4
Joined: Fri Jun 25, 2004 11:48 am

Post by ipb1024-ipb »

What you could do is capture the http referer value into a hidden form field when the user requests the shopping cart page. Store that value until he moves out of it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You could potentially use sessions for this. Since referer may not be passed by the visitor. We've got a lot of threads on sessions for things like this here.
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Thank you, ipb1024-ipb and feyd. I'd considered using a session variable, but was holding back until I'd found out if there was something built-in to handle URL "depth." I appreciate your replies, and will probably go with the session variable! :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

other than using javascript to go back in their history (which, since client-side may be turned off) .. I don't know of any functionality in php's core that has history information. About the only thing I can figure for getting an accurate history on a visitor (although this may fluctuate) is tracking the IP and Session ID, then dynamically looking in the server logs for their walked path..
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

Yeah, that's precisely why I'm staying away from JS. Even though the VAST majority of our users wouldn't even begin to know how to turn off their JS, I only like to use it for specific things, like client-side validation (with server side as well, of course :) ), form calculations, etc.

I suppose, like you mentioned, I could track the user's history. But, for how small of a shopping site we've got it wouldn't be worth the trouble of implementation, at least at this stage. Although, when we get to the point of diving deeper into this project it might be valuable enough to consider.

And, again, thanks, feyd, for your response. As always, I'm thankful of the helpful replies that I've always received in this forum, but in this thread I'm especially inclined to show my appreciation! :wink:
Post Reply