浏览器:刷新时Cookie丢失

Nir*_*mal 10 php browser cookies

我在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);
Run Code Online (Sandbox Code Playgroud)

这是我用于页面标题的内容:

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
Run Code Online (Sandbox Code Playgroud)

您是否在此处看到可能影响Cookie处理的任何问题?谢谢你的任何建议.

编辑-01:

似乎cookie没有发送一些请求.这种情况间歇性地发生,我现在看到所有浏览器的这种行为.有人遇到过这种情况吗?是否有任何情况下cookie不会随请求一起发送?

编辑-02:

以下是HTTP标头:

Request Method:GET
Status Code:200 OK
Run Code Online (Sandbox Code Playgroud)

请求标题

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
Run Code Online (Sandbox Code Playgroud)

响应标题

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
Run Code Online (Sandbox Code Playgroud)

再次感谢,任何指南.

Jam*_*are 4

看到你的头信息后,我唯一能想到的是 PHP 在你设置 cookie 之前输出一些东西。如果是这种情况,setcookie 应该返回 false,并且您将收到警告“无法发送会话 Cookie - 标头已发送”正如 Bart S. 建议的那样,打开error_reporting(E_ALL)并尝试输出 setcookie 的返回值以验证这不是案件。

另外,尝试setcookie在基本情况下仅使用名称和值,然后再次检查响应标头。然后删除除 setcookie 之外的所有代码,如果有效,请使用分治法恢复所有代码:)