开发者

setcookie for little time doesn't work in non-firefox

While testing some scripts, I've noticed, if expiration time is little (not zero) - cookie isn't available in Chrome, Opera, IE.

Example:

<?php
// setting cookie for 5 minutes
setcookie( 'cookie1' , 'Test', time()+60*5 );
echo $_COOKIE['cookie1'];
// yeap (it should display it only with refresh of page - I know:)
?>

In Firefox - I see the word Test (after opening and refreshing the page).

But in other browser - I don't see this. If I change time to time()+60*100 for example - it works fine in all browsers.

What's the reason of this?

UPD:

开发者_运维技巧

From Chome Dev Tool (sorry, don't know how Chrome firebug is called):

Date:Sun, 22 May 2011 10:29:59 GMT
Keep-Alive:timeout=15, max=99
Server:Apache/2.2.14 (Ubuntu)
Set-Cookie:Maslo123=Test; expires=Sun, 22-May-2011 10:34:59 GMT

Date is early than 'expires';


As we have already acquired that your server’s time is wrong by few hours and thus the cookies are already expired.

The reason why Firefox still stores the cookie might be that it detect the odd time difference between the server and the client and uses the difference between the Date value and the Expires attribute value to determine the cookie expiration date.

These issues are also the reason why latter RFC standards like the current RFC 6265 prefer the relative time value of delta seconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜