从IE中的其他域获取cookie [英] Get cookies from another domain in IE
问题描述
我有以下内容:
用户点击链接 mydomain.com/redirect.php
通过 setcookie
函数获取cookie(对于mydomain.com),然后转到另一个页面( header('Location:...');
) - 说 lp.html
User clicks on a link mydomain.com/redirect.php
where gets a cookie (for mydomain.com) via setcookie
function and then goes to another page (header('Location: ...');
) - say lp.html
然后,在该页面上有一个脚本:
gs('mydomain.com/getcookie.php','client = 52',function(){});
,此函数如下:
Then, on that page there is a script:
gs('mydomain.com/getcookie.php', 'client=52', function() {});
and this function is as follows:
gs = function(path, args, fn) {
var p = document.head || document.getElementsByTagName("head")[0]
var s = document.createElement("script");
p.appendChild(s);
if (fn) {
if (s.addEventListener) {
s.addEventListener('load', fn, false);
} else if (s.attachEvent) {
s.attachEvent("onload", function() {
fn(window.event)
});
} else {
s["onload"] = fn;
}
s.onreadystatechange = function() {
fn()
}
}
s.src = path + "?" + args;
}
getcookie.php
script从 $ _ COOKIE
获取一个值(因为它在我的域中)并返回一个小的js,如下所示: myParam ='cookieValue';
以后在js中使用。
The getcookie.php
script gets a value from $_COOKIE
(since it's on my domain) and returns a small js, like this: myParam = 'cookieValue';
for later use in js.
所以,这很好用......除了Internet Explorer。只有当我手动允许它接受所有cookie时才能在那里工作。
So, this works well... except Internet Explorer. It works there only if I manually allow it to accept all cookies.
回答 :(感谢duellsy)
answer: (thanks to duellsy)
添加
header('P3P: CP="CAO PSA OUR"');
header('P3P: CP="HONK"');
推荐答案
IE有一些cookie安全的东西可能很难诊断,尝试将其添加到页面顶部
IE has some cookie security things that can be hard to diagnose, try adding this to the top of your page
<?php header('P3P: CP="CAO PSA OUR"'); ?>
查找Internet Explorer P3P,了解更多相关信息
Look up Internet Explorer P3P, to find out more information on this
关于这是什么的SO的良好回应: https://stackoverflow.com/a/5258105 / 1613391
A good response on SO on 'what' this is: https://stackoverflow.com/a/5258105/1613391
这篇关于从IE中的其他域获取cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!