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.
Pages
Categories
Blogroll
- Branch
- Daily Kos
- Datascraper
- Digg
- Drewvis
- Endgadget
- Eschaton
- Gizmodo
- Imputor? Records
- Inside The Kings
- Lou’s Records Blog
- MetaFilter
- Mostly Un-interesting
- Mozillazine
- pickRset
- Piggington
- Reverdesen
- Slashdot
- Space.com
- Think Progress
- Tum Yeto
- Two Empty Nesters
Archive
- July 2010
- April 2010
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- April 2008
- March 2008
- February 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- April 2007
- March 2007
- February 2007
- December 2006
- October 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- April 2005
- March 2005
- February 2005
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 ‘/’