Home » PHP

PHP: Cookies expiring too early in Safari (Win)

9 October 2009 No Comment

There appears to be an issue with cookies on Windows Safari that expires  at UTC time and not according to the time zone on your machine.

I tested my PHP code

setcookie("mycookie", $sample_session_variable, time()+10000,'/mydirectory/','mysite.com');

I verified that the cookie expires at the correct time for the following browsers

  • Firefox 3.5
  • Internet Explorer 8
  • Safari (Apple OS X)

However,  Safari 4 (Windows) have cookies are expiring at UTC time.

So if you have are using PHP cookies (or any other scripting language) and they don’t work in Safari, the cause may be the expiration date.

If you plan to have you cookies expiring after more that 24 hours, its not an issue. Its best to set the time() + value to 86400 at the very minimum. This is to ensure Safari (Win) users will have functioning cookies.

setcookie("mycookie", $sample_session_variable, time()+86400,'/mydirectory/','mysite.com');

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.