我在IE中有一个奇怪的古怪的Cookie。当用户登录网站时,我正在生成一个新的 session ID,因此需要覆盖cookie。流程基本上是:
https://secure.example.com/users/login
页面,自动接收 session ID https://secure.example.com/users/mypage
:CAKEPHP=deleted; expires=Sun, 05-Apr-2009 04:50:35 GMT; path=/
CAKEPHP=98hnIO23...; expires=Mon, 12 Apr 2010 04:50:36 GMT; path=/; secure
https://secure.example.com/users/mypage
,并提供新的 session ID。 此功能适用于除IE(已在7和8中测试)以外的所有浏览器。 IE会保留未经身份验证的旧 session ID,然后重定向回登录页面。它适用于我的本地测试环境(使用
https://localhost:8443/...
上的自签名证书),但不适用于实时服务器。我使用的是CakePHP,只需发出
$this->Session->renew()
,它会产生上述cookie头。任何想法如何使IE接受新的cookie?
这是完整的标题:
HTTP/1.0 302 Moved Temporarily
Date: Thu, 08 Apr 2010 02:54:30 GMT
Server: Apache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Set-Cookie: CAKEPHP=deleted; expires=Wed, 08-Apr-2009 02:54:30 GMT; path=/
Set-Cookie: CAKEPHP=d55c...; expires=Thu, 15 Apr 2010 02:54:31 GMT; path=/; secure
Last-Modified: Thu, 08 Apr 2010 02:54:30 GMT
Location: https://secure.example.com/users/mypage
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html; charset=utf-8
我想我已经发现了问题:
IE会发送两个同名的Cookie。这是对服务器的下一个请求:
GET /users/mypage HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */ *
Referer: https://secure.example.com/users/login
Accept-Language: en-gb
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322)
Accept-Encoding: gzip, deflate
Host: secure.example.com
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: CAKEPHP=19c6...; CAKEPHP=d55c...
请注意,它发送两个cookie,一个是登录后收到的cookie,另一个是旧的cookie。它在主页
example.com
上收到了旧的,并设置了path=/
。它还会将其发送给secure.example.com
请求。它不会被上述标题替换,而是将其添加为其他cookie。我该如何阻止它呢?
最佳答案
确保为您的基本域发出了cookie。
这很可能是问题所在,因为这种行为在不同的浏览器中肯定会有所不同。
我还没有在cakephp中做到这一点,但是this should work
关于internet-explorer - Cookie无法在IE中更新/覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2577026/