Page 1 of 1

setting cookie information

Posted: Fri Jan 15, 2010 9:01 am
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

Re: setting cookie information

Posted: Fri Jan 15, 2010 5:25 pm
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.