views:

51

answers:

2
+1  Q: 

php shopping cart

Hi,

im doing a shopping cart and everything works well until i realise something. currently im using session to track user's cart items into the database. user can add items to cart without login. however, before checkout, users will need to login to do so. when user login, the session_id() will be re-generated. this means that it will be different from the session_id used to store those cart items b4 login. how am i gonna track user cart items then??

+1  A: 

You could define the session_id when logging-in the user - creating the "logged in" session with the same session ID as the "not logged in" session.

http://www.php.net/manual/en/function.session-id.php

matthewh
Great! I've had this problem before too where restarting the session upon authentication loses my old session. Thanks!
Delan Azabani
tks man.. i will use this method..
@Delan why restart session at all?
Col. Shrapnel
Hi col.shrapnel, I had to restart session because when i validate for user's login, i sort of clear all existing session. now that you mention, i've modify my code not to clear any existing session and continue reusing the same one. it makes things easier....tks man!!
A: 

There are two ways,

1) You can maintain same session as suggested by matthewh

2) You can maintain shopping details in database with session id

Hope this helps.

Yogesh