【问题标题】:Cookies inside script-tag include on cross domainsscript-tag 中的 Cookie 包含在跨域中
【发布时间】:2011-12-01 21:09:59
【问题描述】:

所以我在一个域上有这个页面,它有一个指向另一个域的脚本标签,每次我刷新页面时,都会生成一个新的 session_id。这只发生在 IE 上,所有其他浏览器似乎都可以工作。

这里是一个代码示例(JS 和 PHP)

http://domain1.com/index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://domain2.com/index.php"></script>
</head>
<body>
</body>
</html>

http://domain2.com/index.php 上:

<?php
    session_start();
    header("content-type: application/x-javascript");
    echo "alert('".session_id()."');";
?>

在 domain1.com/index.php 中打开 Chrome 或 Firefox,您应该会看到一个带有会话 ID 的警告框。每次刷新时,您始终拥有相同的会话 ID。 在 IE 中(我尝试使用 7、8 和 9),会话 ID 总是不同的。 cookie 似乎没有正确保存。

感谢您的帮助。

【问题讨论】:

  • 有人认为可以做到吗?
  • 我发现 Internet Explorer 中隐私策略的默认值是 Medium,它说:阻止没有紧凑隐私策略的第三方 cookie 如果我将其设置为全部允许,它可以工作.但是有没有办法绕过这个?

标签: javascript internet-explorer cross-domain


【解决方案1】:

出于文档目的,这是我找到的解决方案:

我使用 IBM P3P 策略编辑器创建了一个 p3p 文件(p3p 和 CP 文件) 上传文件夹 /w3c 中的文件 并在domain2.com P3P上的文件中添加了如下头:CP="content from the CP generated file"

【讨论】:

  • 你让我开心,弗兰克。在我的 PHP 服务器文件中添加了 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"'); 并像魅力一样工作。 IE 总是那么...(咳咳)有点好笑...
猜你喜欢
  • 2014-01-13
  • 1970-01-01
  • 2014-04-27
  • 2014-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-19
  • 2012-10-08
  • 1970-01-01
相关资源
最近更新 更多