note 49200 added to function.setcookie

From: Date: Thu, 20 Jan 2005 00:05:29 +0000
Subject: note 49200 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-83645@lists.php.net to get a copy of this message
Found an interesting "feature" with Firefox 1.0 and setting cookies. We tested it with IE, and Win2K and XP Pro, and it's definitely Firefox. If you have a script set a cookie without setting a path, it uses the path that the script is stored in, for example if you set a cookie in a script called: /accts/login.php Then the cookie path is "/accts" when you examine the cookie that's set. If you try to "unset" a cookie with the standard format from a script that isn't in the same path, for example: /inc/logout.php Then the following code WILL unset a cookie under IE but NOT Firefox 1.0: <? set_cookie ("COOKIE", "", time() -3600); ?> The problem is that COOKIE was set with a path of "/accts" but the logout.php code has a path of "/inc" so under Firefox it doesn't match (whereas IE doesn't check.) The following will work: <? set_cookie ("COOKIE", "", time() -3600, "/accts"); ?> Basically, in Firefox, if you can't remove cookies, be sure to check the domain and path attributes of the cookies that are set, and if need be, specify them in the code where you try to remove those cookies. Took a couple of hours to figure this out. Cheers! ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49200 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49200&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49200&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49200&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49200&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49200&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49200&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83645) next »