简体   繁体   English

setcookie很少时间在非Firefox中不起作用

[英]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. 在测试某些脚本时,我注意到,如果到期时间很少(不为零)-Chrome,Opera,IE中不提供cookie。

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). 在Firefox中-我看到了单词Test(在打开并刷新页面后)。

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. 例如,如果我将时间更改为time()+60*100在所有浏览器中都可以正常工作。

What's the reason of this? 这是什么原因?

UPD: UPD:

From Chome Dev Tool (sorry, don't know how Chrome firebug is called): 从Chome Dev Tool(抱歉,不知道如何调用Chrome firebug):

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. 我们已经知道您的服务器的时间错误了几个小时,因此cookie已经过期。

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. Firefox之所以仍然存储cookie,可能是因为它检测到服务器和客户端之间的奇数时间差,并使用Date值和Expires属性值之间的差来确定cookie的到期日期。

These issues are also the reason why latter RFC standards like the current RFC 6265 prefer the relative time value of delta seconds. 这些问题也是后来的RFC标准(例如当前RFC 6265)偏爱增量时间的相对时间值的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM