Cookies with PHP’s setcookie() and Safari
I've come across a little inconsistency between browsers and the way they handle cookies. Using the examples from PHP's online manual, I was unable to get Safari to remove cookies using setcookie(). All other browsers would clear the cookie with no problems. It turns out that Safari will only delete cookies if both the cookie name AND the cookie path match.
In other words, this won't work:
setcookie('TestCookie', 'somevalue', time()+3600, '/somepath/'); // Set cookie
setcookie('TestCookie', '', time()-3600); // Delete cookie
But this will work:
setcookie('TestCookie', 'somevalue', time()+3600, '/somepath/'); // Set cookie
setcookie('TestCookie', '', time()-3600, '/somepath/'); // Delete cookie
Basically, if you set a cookie using a path, you must also specify the path when deleting the cookie. Safari won't remove the cookie otherwise. This is probably a good thing.
Pay Da Billz
Categories
- Cooking Recipies (1)
- Hockey (2)
- Misc (7)
- Music (3)
- Politics (12)
- San Diego (6)
- Wildfires 2007 (3)
- Tech (81)
- Apache (11)
- Apple (17)
- AppleTV (1)
- iPhone (6)
- App Store (1)
- iPod/iTunes (6)
- OS X (2)
- Database (4)
- MySQL (2)
- PostgreSQL (2)
- FCKeditor (3)
- FreeBSD (7)
- Google (1)
- Hardware (11)
- Linux (15)
- Mozilla (1)
- Thunderbird (1)
- phpList (6)
- Postfix/Sendmail (3)
- Programming (18)
- Windows (8)
- World of Warcraft (3)
January 28th, 2009 - 06:54
I noticed something strange in Iphone. I´m still able to set and retrieve cookies on Iphone Safari, even after going to Safari Settings and disabling cookies (set to never accept cookies). Anyone else experienced this ?
February 3rd, 2009 - 19:46
This works fine, but is useless when the path is just a slash ‘/’
December 25th, 2010 - 08:49
so what can be done with a slash as a path??
Seems it’s impossible to delete cookies in safari, using the root path(