Reputation: 27
I try to execute a shopping cart .In the beginning I save the selected products in an array SESSION while the customer order doesn't complete. But,my work was imperfect because I don't use the session ID and I don't insert the selected products to database,therefore I can't management the sessions. Now, I want to improve my code to get an unique sessionID for each customer. I see more examples in this issue and here I want to know which better to use:
//session_id($_GET['PHPSESSID']); session_start();
$session_id=session_id('PHPSESSID');
-OR-
session_start();
$sessionID = $_COOKIE['PHPSESSID'];
then,I will save the selected products to db width this $session_id.
note that, I use a simple way to complete the customer order and store the selected items to db, which is via customer email verification .after custmer verify his/her email I want to go back him/her to a page that he/she can update his/her cart items or continue shopping. here how to get the $session_id to do that successfully. please guide me in this issue.Thanks
Upvotes: 0
Views: 2937
Reputation: 775
Just store session id in cookie until (2 day for example) user return to site after email verification and then finish the order.
Upvotes: 1
Reputation: 378
They both should return the same thing its just two different ways of referencing it. Although I would recommend against keying your users against session ids because the user can delete the cookie (which is where the id is stored) at anytime or it can expire and then you will have to create a whole new user which will cause you to lose all your records every time. I recommend keying your users against a primary key in the database.
Upvotes: 3