我正在尝试设置依赖Cookie来识别用户的Web服务。 有时这些是第一方cookie,即用户在我的网站上收到它们(例如my-site.com);其他时候使用my-site.com提供的图像从其他网站设置/读取cookie。
问题是在IE中(至少在IE8中),在这两种情况下,cookie都被正确设置和读取(持久性,而不是会话cookie),它们被视为2个单独的cookie。即我的网站为同一个用户分配了2个不同的UID,无法为其他网站执行正确的服务。
我在HTTP响应中设置了一个P3P标头(没有第三方cookie被视为会话cookie)。
在Chrome和Mozilla中,这可以正常工作,即设置为第一方的Cookie在从其他网站连接时作为第三方返回,反之亦然。
这是来自Fiddler的HTTP请求/响应转储:
HTTP请求:(第一方)
GET http://my-site.com/redirect_to?eid=100 HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: he-IL
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; Tablet PC 2.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: my-site.com
Cookie: uid=8943448674338503051
HTTP响应:(第一方)
HTTP/1.1 302 FOUND
Date: Thu, 13 Jun 2013 12:22:31 GMT
Server: Apache/2.2.22 (Ubuntu)
P3P: CP="CUR CUS OUR BUS UNI NOI"
Location: http://google.com
Set-Cookie: uid=8943448674338503051; expires=Tue, 12-Jun-2018 12:22:31 GMT; Max-Age=157680000; Path=/
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
HTTP请求:(第三方)
GET http://my-site.com/pixel?eid=100 HTTP/1.1
Accept: */*
Accept-Language: he-IL
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; Tablet PC 2.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: my-site.com
Cookie: uid=6926889931739290944
HTTP响应:(第三方)
HTTP/1.1 204 NO CONTENT
Date: Thu, 13 Jun 2013 12:22:12 GMT
Server: Apache/2.2.22 (Ubuntu)
P3P: CP="CUR CUS OUR BUS UNI NOI"
Content-Length: 0
Set-Cookie: uid=6926889931739290944; expires=Tue, 12-Jun-2018 12:22:12 GMT; Max-Age=157680000; Path=/
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8