setting cookie information

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

setting cookie information

Post by kevrelland »

Hi,
i was wondering if it is possible for me to set a cookie which will accept a value from a page ie product id number and then when they view another page it adds to the existing cookie the second product id number and so on.
Any ideas
Cheers
Kev
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: setting cookie information

Post by Skara »

See php.net/setcookie.

I think this is what you're asking:

Code: Select all

$product_ids = empty($_COOKIE['product_ids']) ? '' : explode(';',$_COOKIE['product_ids']);
//some code
$product_ids[] = $new_id;
//some more code
implode(';',$product_ids);
setcookie('product_ids',$product_ids, ... );
Not really a "Theory and Design" question.
Post Reply