I’m writing a simple shopping cart in PHP, but I’m not quite sure how I should store the items a users selects to purchase. Should I use cookies? Of course, if I did use cookies, all I would store in the cookie is the item SKU and quantity. I wouldn’t store the prices in the cookies, since the user could potentially change them.
Thanks for your advice!
I suggest storing the shopping cart items in the user’s session (
$_SESSIONvariables). If you need them to persist across sessions, put them in a database table.In session variables, they’re safe from tampering (they’re on the server side) and you don’t have to worry about information disclosure (all that’s in the cookie or
GETparameter is the session ID).