I am having trouble getting cookie information from domain A to domain B, using jsonp. I've got it working for Chrome and Firefox et al., but for IE it does not work. I am doing a jsonp request from domain B to domain A that sets a cookie there through php on domain A and then I do a check for that same cookie from B again. The information in the cookie is then printed to screen (domain A), so that I can pick that up from domain B and set a cookie there that mirrors that information (I am aware of the security risks, I am not trying to sync sensitive information here, just a setting).
So, as said, this is working on FF, Chrome etc. But on IE, I see that only session cookies are returned, which the cookie that I set isn't (and shouldn't be).
Any clue what's wrong here? Or isn't this even possible? I also briefly tried CORS, but that has the same problem.
I have the following test setup:
Domain A: (central domain)
login.php
<?php
//below line solves the problem. See accepted answer
header('P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"');
setcookie("loggedin","5",time()+3600);
echo 1;
check.php
<?php
//below line solves the problem. See accepted answer
header('P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"');
$cookies = implode('; ', array_map(function ($v, $k) { return $k . '=' . $v; }, $_COOKIE, array_keys($_COOKIE)));
if(isset($_COOKIE['loggedin'])&&($_COOKIE['loggedin'] == "5")) {
echo "alert('logged in, ".$cookies."');";
} else {
echo "alert('not logged in, ".$cookies."');";
}
Domain B:
jsonp.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<h1>hi!</h1>
<script>
jQuery.ajax({
url: 'http://cookies.hidev.nl/login.php',
dataType: 'jsonp',
type: "get",
});
//note: first call will set the cookie, next succeeds only after reload due to async loading. This is only for test purposes
jQuery.ajax({
url: 'http://cookies.hidev.nl/check.php',
dataType: 'jsonp',
type: "get"
});
</script>
</body>
</html>