logo 西林@生存 - 骑猪闯天下!
iframe cookie的设置问题
2007-9-13 18:06:00 By:xling

做了一下测试,

环境:IE7

两个域名:www.testa.com  www.testb.com

在testa.com的一个页里,用iframe请求testb.com的一个页面。

两个页里均设置cookie,发现只有testa.com的cookie设置成功,testb.com的cookie设置不成功。

示例代码如下,以证明:

testa.com

<?php
 setcookie("pId","nickr",time()+3600);
?>
<!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>无标题文档</title>
</head>

<body>
<script language="javascript" type="text/javascript">
document.write(document.cookie,"<br />");
</script>
<iframe src="http://www.testb.com/test/b.php"></iframe>
</body>
</html>

 

testb.com

<?php
 setcookie("aId","xling",time()+3600);
?>
<!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>无标题文档</title>
</head>

<body>
<script language="javascript" type="text/javascript">
document.write(document.cookie);
</script>
</body>
</html>

 

运行后,抓图:


iframe页的cookie没有显示!说明testb.com的cookie设置不成功!

Over!此乃跨域问题!

转我的贴,写你的名,是一种可耻的行为!请不要让我BS你!
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    密码:
    主页:
    标题:
    页面数据正在载入...
<<  < 2008 - >  >>
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Placard
请职:PHP或JS都行,如果学历要求本科的,请直接忽略。谢谢。 有意者请联系:1fairy1#163.com
Logon System
Search
Info about this blog
Others
myDream
JGrid

数据表格
JTree

树状控件
JMenuTab

标签控件(滑动门)
JTrackBar / JScroll

滑动条/模拟滚动条
JAccordion

(QQ菜单)
关于:
xling,也叫xlingFairy 艾克司令 西林.
Email:1fairy1#163.com
喜欢javascript,喜欢java(汗...还在学习中...水平菜的要死...)
bxna 京ICP备05002321号