Cookies for shopping cart

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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Cookies for shopping cart

Post by aceconcepts »

Hi,

I have built a shopping cart using php. I am currently using session variables to store session_id() in order to identify the products in a users cart.

How can I use cookies to do the same thing?

Thanks.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I don't know why you'd want to. But, instead of setting the session variables, set the cookies.

Code: Select all

$_SESSION['prod_id'] = 11345614;
Would become...

Code: Select all

setcookie('prod_id',11345614,time()+x);
Of course you may wish to store things in arrays and serialize them to send to a single cookie.
Last edited by s.dot on Thu Sep 28, 2006 6:46 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Thanks.
Post Reply