2

好的,这是我的情况。

我有一个页面 index.php,它是主站点(flash 站点)

我有另一个名为 iframe.php 的页面,其中包含 index.php 的 iframe

另一个页面,test.php。里面有2个链接,第一个链接直接指向index.php,另一个链接指向iframe.php

我测试过:

  • 我单击第一个链接,当我跟踪/回显 HTTP_REFERER 时,它显示“test.php”,但是

  • 我单击第二个链接,当我跟踪/回显 HTTP_REFERER 时,它显示“iframe.php”。

为什么它显示“iframe.php”?HTTP_REFERER 在 iframe 上不起作用吗?

当我点击第二个链接时,是否有办法获得“test.php”?

:index.php 的源代码

<html>
<head> // Some headers information
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
    <?php
if(!empty($_SERVER['HTTP_REFERER'])){
?>
    flashvars.link       =  '<?php echo $_SERVER['HTTP_REFERER']; ?>';
<?php
}
?>
var params = {};
var attributes = {};
swfobject.embedSWF("main.swf, "content", "100%", "100%", "9", "expressInstall.swf", flashvars, params, attributes);
</script>
</head>
<body>
    <div id="content">
    <a href="http://www.adobe.com/go/getflashplayer">
            <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
        </a>
    </div>
</body>
</html>

iframe.php 的源代码

<html> headers tag
...
<body>
<center><iframe src="index.php" mce_src="index.php" frameborder="0" height="500" scrolling="no" width="500"></iframe></center>
</body>
</html>

test.php 的源代码:

....
<a href="iframe.php" target="_blank">This is Iframe</a> <br><br>
....
<a href="index.php" target="_blank">This is normal link</a> <br><br>
4

2 回答 2

1

无论哪种情况,您都会看到index.php. 原因如下:

场景 1)

当您index.php从 中的链接点击时test.php,它会加载index.phptest.php作为HTTP_REFERER)。

方案 2)

当您iframe.php从 中的链接点击时test.php,它会加载在标签iframe.php内部加载的内容(使用as )。index.php<iframe>iframe.phpHTTP_REFERER

于 2009-12-18T04:12:57.253 回答
0

抱歉不行。在 iframe 中显示的页面的 HTTP_REFERER 值将始终是包含 iframe 的父页面。

无论如何,HTTP_REFERER 往往有点难以指望。如果您可以避免围绕它构建任何重要的逻辑,那么这样做是个好主意。

我猜你正在使用 php——也许你可以使用 session 来存储 test.php 加载时访问的最后一页?在 test.php 上,您设置$_SESSION['referringPage'] = 'test.php';. 然后在 index.php 上,您读取 的值$_SESSION['referringPage'],无论页面是否在 iframe 中加载,您都会获得相同的信息。

于 2009-12-18T04:24:12.223 回答