Page 1 of 1

cookie problem!

Posted: Mon Feb 28, 2005 12:43 am
by shiznatix
im trying to assign a cookie with a diffrent value for every user so the cookie has your user ID. heres my code

Code: Select all

$sessID = session_id();
if (!isset($_COOKIEї'cartID'])){
setcookie('cartID', $sessID, time()+60*60*24*30, '/', '', 0);
}

$cartID = $_COOKIEї'cartID'];
but it dosn't work properly, when i close my browser and open it back up to destroy the session the cookie is no longer set. with this at the top of the script i would always have a cookie am i correct? but i tried adding in this right after those lines of code

Code: Select all

if (!isset($_COOKIEї'cartID'])){
die('You Must Have Cookies Enabled');
}
but when i destroyed the session it would give me the die error, but i didnt delete the cookies? plus wouldnt the cookie already be set anyway if it did not exist by the lines directly before this? im confused

Posted: Mon Feb 28, 2005 2:01 am
by n00b Saibot
your code works for me real fine! But One thing, the code you posted doesn't have a session_start in the start though. Have you also left it out in your original script ? Maybe that is causing it not to work.

Posted: Mon Feb 28, 2005 2:05 am
by feyd
do you switch parts of domains throughout the site? For instance, if you start at http://www.foo.com and transfer to foo.com the cookie will not exist on foo.com .. this is due to how you are setting it. A domain value of '.foo.com' will make the cookie available to all of the domain. Note the leading dot.

Posted: Mon Feb 28, 2005 2:48 pm
by shiznatix
ok now its working (kinda?) i dunno its real strange and works sometimes and other times it does not. maybe its my browser? i use firefox. dunno