note 65650 deleted from function.setcookie by danbrown

From: Date: Sun, 17 May 2009 17:58:03 +0000
Subject: note 65650 deleted from function.setcookie by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155045@lists.php.net to get a copy of this message
Note Submitter: matt at mattsoft dot net ---- using time()-1 to delete (expire) a cookie only works if the client's clock is set exact. my testing showed some weird results with my clock set 1 second or so behind the server. 1 day or even just a few seconds ahead of the server's time and the cookie doesn't expire when it's suposed to. my test: setcookie('k',$k+1,time()-1); echo $k; setting the expire time to 0 makes it a browser session cookie, lasting forever, until the browser is closed. but setting the expire time to 1 is the lowest timestamp possible and is most likely to expire the cookie without any problems. my fix: setcookie('k',$k+1,1); echo $k; this is my theory. I'm not sure why no one else has thought of this problem or solution, and I'm still testing, but please email me your questions or comments.

« previous php.notes (#155045) next »