note 34531 added to function.setcookie

From: Date: Wed, 30 Jul 2003 04:38:06 +0000
Subject: note 34531 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-52988@lists.php.net to get a copy of this message
I just bought a shared webhosting account and I was testing my server. For some strange reason, setcookie() was returning TRUE but was not creating a cookie in my browser. I spent a good hour trying to figure out the problem. my script was cookiemaker.php -------------- <?php setcookie("SID", "abc", time()+10000, "/", ".foobar.com", 0); ?> -------------- The above would not properly set a cookie in my browser. When i changed the expiry from time()+10000 to time()+100000 it worked!! My only explanation for this is that I live on the east coast (Toronto) and the server is located in California. Setting an expiry of time()+10000 actually sets the expiry to a date in the past (relative to Toronto), while time()+100000 sets an expiry date in the future (relative to Toronto). This would explain why I had no problem with setcookie() with my local server in Toronto. So if your setcookie is returning true but not setting a cookie, check the expiry time (and, of course, the path and domain parameters). Hope this helps, Sandy. ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34531 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34531&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34531&report=yes

« previous php.notes (#52988) next »