session question

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
apdragon
Forum Newbie
Posts: 5
Joined: Thu Apr 05, 2007 1:18 pm

session question

Post by apdragon »

Hi I'm kinda new at this but I am having some trouble with sessions. Lets say I have multiple shopping carts for customers and they go to one site to order something and then adds it to the cart (this is where the session starts) then goes back and if they go to another site and trys to order something else, in the other sites shopping cart it would show the variables from the first site in the shopping cart? My question is how can I differentiate or start a new session ID if they go to another site? because I am using the same code in each shopping cart. So if they were to go to one site and add things to that cart and not checkout yet......then goes to another site and adds things to that cart the items from the first cart is not added to the second cart. but then if they go back to the first their items are still there?? I hope that makes sense.....Any Help would be much appreicated....Thanks in Advance
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

You're trying to bridge shopping carts between two sites you run? Are they on the same server?
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

It's kinda tricky. Yes, if the both site runs on the same server, then it might open a possibility for doing something like that.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

http://tinyurl.com/2jzw8d might be of interest - it sounds like a lot of work, but could be worth it!
apdragon
Forum Newbie
Posts: 5
Joined: Thu Apr 05, 2007 1:18 pm

Post by apdragon »

I'm not trying to bridge shopping carts.....but keep them seperated so one person can't order from another site. Thats why I was thinking of having a unique session ID?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are the shopping carts on the same domain?
apdragon
Forum Newbie
Posts: 5
Joined: Thu Apr 05, 2007 1:18 pm

Post by apdragon »

yes they are
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You're cookies are going to be transposed I believe, since the sessions are happening on the same domain. You might consider setting a session variable with an ID of the shopping cart so you always know which one you are in.
apdragon
Forum Newbie
Posts: 5
Joined: Thu Apr 05, 2007 1:18 pm

Post by apdragon »

I'm not sure if that will work for me........but i will try it. Lets say I start a session in the shopping cart and populate an array $cart and register that, go back to the website go to another site and add an item to the cart that will populate array $cart, won't that array have both items in it since I registered that array?

How do I keep the sessions separate so the array doesn't have both items....if that makes sense??
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Say you have four carts, one each for music, posters, books and shirts. Since each cart is on the same domain (unless you specify certain information for your session cookies using something like session_set_cookie_params() ) your cookie will reference one session. That is ok, as long as each cart is identified in your session array. Give each cart an identifier, then use that identifier when you are in that particular cart to keep track of things in that cart, so the carts don't mix.
Post Reply