浏览器:饼干丢失刷新 [英] Browser: Cookie lost on refresh

查看:165
本文介绍了浏览器:饼干丢失刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到我的Chrome浏览器的应用程序(与其他浏览器没有问题)的一个奇怪的行为。当我刷新页面,该cookie被发送正确,但间歇性的浏览器似乎并没有将一些刷新该cookie。

这是我怎么设置我的cookie:

  $标识= /有些怪异的串/;
$键= MD5(uniqid(RAND(),真));
$超时= number_format(时间(),0,'''')+ 43200;
的setcookie('fboxauth',$标识符:。$键,$超时,/,fbox.mysite.com,0);

这是我使用页眉内容:

 标题(上次修改:gmdate(D,D M Y H:我:秒。)GMT);
标题(缓存控制:无缓存,必重新验证); // HTTP / 1.1
标题(截止日期:星期四,1982年11月25日8点24分00秒GMT); //过去的日期

你看到任何问题,在这里,可能会影响cookie处理?谢谢你的任何建议。

编辑-01:

似乎cookie不会被一些请求发送。这发生间歇和我现在看到这种行为所有的浏览器。有没有人遇到过这样的情况?是否存在这样的cookie不会与请求一起发送的情况呢?

编辑-02:

下面是HTTP标头:


 请求方法:GET
状态code:200 OK


请求头


<$p$p><$c$c>Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
引用者:HTTP://fbox.mysite.com/dashboard
用户代理:Mozilla的/ 5.0(视窗; U; Windows NT的6.1; EN-US)
为AppleWebKit / 532.5(KHTML,例如Gecko)
镀铬/ Safari浏览器4.1.249.1045 / 532.5


响应头


 的Cache-Control:no-cache的,必重新验证
内容长度:8903
内容类型:text / html的
日期:星期二,2010年4月6日9点25分26秒GMT
到期日:星期四,1982年8点24分00秒格林尼治标准​​时间11月25日
最后一次修改:星期二,2010年4月6日9时25分26秒GMT
编译:无缓存
服务器:Microsoft-IIS / 7.5
的X已启动方式:PHP / 5.3.1 ZendServer对其进行访问


再次感谢,对任何指引。


解决方案

我能想到的,唯一看过你的头信息,就是你设置Cookie之前PHP是输出的东西。如果是这样的话,应该的setcookie返回false,你会得到一个警告无法发送会话cookie - 已经发送了头作为巴特S.表明,打开使用error_reporting(E_ALL)并尝试输出的setcookie的返回值来验证这是不是这样的。

此外,尽量只使用的setcookie 中只是一个名称和值的基本情况,并再次检查响应头。然后剪下所有code的除外的setcookie,如果这样的作品,用除法把所有code背部和征服:)

I am experiencing a strange behaviour of my application in Chrome browser (No problem with other browsers). When I refresh a page, the cookie is being sent properly, but intermittently the browser doesn't seem to pass the cookie on some refreshes.

This is how I set my 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);

This is what I am using for page headers:

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

Do you see any issue here that might affect the cookie handling? Thank you for any suggestion.

EDIT-01:

It seems that the cookie is not being sent with some requests. This happens intermittently and I am seeing this behaviour for ALL the browsers now. Has anyone come across such situation? Is there any situation where a cookie will not be sent with the request?

EDIT-02:

Here are the HTTP Headers:

Request Method:GET
Status Code:200 OK

REQUEST HEADERS

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

RESPONSE HEADERS

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

Thanks again, for any guideline.

解决方案

The only thing I can think of, having seen your header information, is that PHP is outputting something before you set the cookie. If that is the case, setcookie should return false and you'll get a warning "Cannot send session Cookie - headers already sent" As Bart S. suggests, turn on error_reporting(E_ALL) and try outputting the return value of setcookie to verify this isn't the case.

Also, try just using setcookie in the basic case with just a name and value and check the response headers again. Then cut out all of your code except for the setcookie and if that works, bring all your code back using divide and conquer :)

这篇关于浏览器:饼干丢失刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆