I have written some code which should GET a variable from a referring page, check if a cookie has been written, if no, store the variable value in a new cookie, if yes, append the variable value to the existing cookie.
When I visit the page for the first time the code stores the variable in the cookie okay. But when I visit the page a second time, instead of appending the data to the existing cookie it overwrites the old cookie with the new value.
I have spent two days trying to see where my code is going wrong, posted to several forums where I am told my code should work okay and I have even compared it with similar code (I won't post it at is would take up too much space) that does append data to the end of the cookie but I can't see that my code is really that much different. I've also read the php manual on cookies and other pages and I can't find anything to help.
Now I'd better show you my code:
if (!isset($_COOKIE['basket'])) {
setcookie('basket', $item_code, time()+60*60*24*30, 'shop') ;
}
else {
setcookie( 'basket', $_COOKIE['basket'].'-'.$item_code );
}
If you run similar code you should be able to check the cookie and see if it appends or not.
$item_code is a number by the way.
I'd be really grateful and relieved if someone would tell me where I am going wrong.
Thanks
Mark