Get cookies from another domain in IE

2019-08-18 06:10发布

问题:

I've got the following:

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

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;
}

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.

So, this works well... except Internet Explorer. It works there only if I manually allow it to accept all cookies.

answer: (thanks to duellsy)

adding

header('P3P: CP="CAO PSA OUR"');
header('P3P: CP="HONK"');

回答1:

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"'); ?>

Look up Internet Explorer P3P, to find out more information on this

A good response on SO on 'what' this is: https://stackoverflow.com/a/5258105/1613391