hello friends,
i am stuck in a situation, plz help, the problem is as follows:
i am making a shopping cart, now the home page of the shopping cart shows item categories, and items under it. There is no account login facility yet as there is no requirement. I am able to start a session and track what items are added by the user to their cart and display them all the items, the users are also able to remove the items from their cart.
Now when someone closes the browser without checking out, the session expires and when the same person visits the same site and adds something to his cart, the old items are not retained, which he had chosen earlier, i am not able to figure out, how can i solve this problem i.e. if the user closes the browser and then re-visits the site in the next 1 or 2 days, he should see the items which was added by him earlier. I am storing the session id and all the items added to cart by him in the database.
Please help.
Thanx.
Gaurav Behl
session-tracking probelm
Moderator: General Moderators
-
gaurav_sting
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 27, 2004 3:45 am
- Location: Delhi
In a nutshell first off all you will *have* to create some kind of login ability, for the sole reason you will need to know who the user is to be able to restore there session at a later date.. you will also need to play around with http://uk2.php.net/manual/en/function.s ... andler.php
When a user logs in; start a session and save its id to the user table(if you decide to use a dbms for storing there info offcourse) with there userid, now when they log out the session data will be retained aslong as you havnt deleted it with a garbage collection routine (see above about session handler). Now when the user comes back you can see what there session id is and restore it with http://uk2.php.net/manual/en/function.session-id.php
Hopes thats makes some kind of sense
When a user logs in; start a session and save its id to the user table(if you decide to use a dbms for storing there info offcourse) with there userid, now when they log out the session data will be retained aslong as you havnt deleted it with a garbage collection routine (see above about session handler). Now when the user comes back you can see what there session id is and restore it with http://uk2.php.net/manual/en/function.session-id.php
Hopes thats makes some kind of sense
-
gaurav_sting
- Forum Newbie
- Posts: 19
- Joined: Sat Mar 27, 2004 3:45 am
- Location: Delhi
session-tracking problem - replied ody's solution
hi,
thanx alot for your help but:
i understand that a user login is necessary for the solution of my problem,
but i wanted if i do not want to implement a user-login supposingly, and assuming that the cookies are allowed by the users, how can i set the cookies so that the next time when the same user visits the site (for next 2 days), some data is picked up from the cookie and the user is shown the items in his/her cart added prevously.
kindly help
Gaurav
thanx alot for your help but:
i understand that a user login is necessary for the solution of my problem,
but i wanted if i do not want to implement a user-login supposingly, and assuming that the cookies are allowed by the users, how can i set the cookies so that the next time when the same user visits the site (for next 2 days), some data is picked up from the cookie and the user is shown the items in his/her cart added prevously.
kindly help
Gaurav
First Id like to make it clear that doing this with cookies is highly insecure.. but anyway yes you can easily do it with cookies using:
http://uk2.php.net/manual/en/function.setcookie.php
Somthing like:
session_start();
if(!isset($_COOKIE[site_name])) { //has the user had a cookie set yet?
setcookie("site_name", session_id()); // set the sessionid for a later date
}else{
session_id($_COOKIE[site_name]); //restore session
}
That may work straight away, maybe not, Ill let you figure the rest out
good luck.
http://uk2.php.net/manual/en/function.setcookie.php
Somthing like:
session_start();
if(!isset($_COOKIE[site_name])) { //has the user had a cookie set yet?
setcookie("site_name", session_id()); // set the sessionid for a later date
}else{
session_id($_COOKIE[site_name]); //restore session
}
That may work straight away, maybe not, Ill let you figure the rest out
good luck.