【发布时间】:2011-02-01 21:21:04
【问题描述】:
我在 Chrome 浏览器中遇到了我的应用程序的奇怪行为(其他浏览器没有问题)。当我刷新页面时,cookie 被正确发送,但间歇性地,浏览器似乎没有在某些刷新时传递 cookie。
这就是我设置 cookie 的方式:
$identifier = / some weird string /;
$key = md5(uniqid(rand(), true));
$timeout = number_format(time(), 0, '.', '') + 43200;
setcookie('fboxauth', $identifier . ":" . $key, $timeout, "/", "fbox.mysite.com", 0);
这是我用于页眉的:
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Thu, 25 Nov 1982 08:24:00 GMT"); // Date in the past
您是否发现这里有任何可能影响 cookie 处理的问题?感谢您的任何建议。
EDIT-01:
似乎某些请求没有发送 cookie。这会间歇性地发生,我现在看到 ALL 浏览器的这种行为。有没有人遇到过这种情况?是否存在cookie不会随请求一起发送的情况?
EDIT-02:
这里是 HTTP 标头:
Request Method:GET Status Code:200 OK
请求标头
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Referer:http://fbox.mysite.com/dashboard User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5
响应标题
Cache-Control:no-cache, must-revalidate Content-Length:8903 Content-Type:text/html Date:Tue, 06 Apr 2010 09:25:26 GMT Expires:Thu, 25 Nov 1982 08:24:00 GMT Last-Modified:Tue, 06 Apr 2010 09:25:26 GMT Pragma:no-cache Server:Microsoft-IIS/7.5 X-Powered-By:PHP/5.3.1 ZendServer
再次感谢任何指导。
【问题讨论】:
-
查看您的服务器发送的确切 HTTP 标头会非常有帮助,并且知道您在哪个服务器/版本/php 版本上运行它?您能否将这些详细信息以及此命令的结果添加到问题中(前提是您在本地运行 linux 变体): curl -I [url_to_your_app]
-
你刚刚试过
$timeout = time() + 43200;吗? -
@Jason:是的,我做到了,但还是一样。
-
尝试删除 setcookie 的路径和域,看看是否是导致问题的原因。还可以尝试启用 display_errors 并将 error_reporting 设置为 E_ALL 以查看是否有任何不太明显的错误。
-
@James:我已经添加了 HTTP 信息。请看一看。顺便说一句,该站点位于装有 PHP 5.3.1 的 Windows 机器上。