问题
Okay, here is my situation.
I have a page, index.php, which is the mainsite (flash site)
I have another page called iframe.php which contain iframe of index.php
Another page, test.php. Inside have 2 links, 1st link is directly to index.php, another link is to iframe.php
I tested:
I click the 1st link, when i trace/echo the HTTP_REFERER, it displays "test.php", but
I click on 2nd link, when i trace/echo the HTTP_REFERER, it displays "iframe.php".
Why it display "iframe.php"? Is HTTP_REFERER does not work on iframe??
Is there anyway to get the "test.php" when i click on second link?
Source code for :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>
Source code for 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>
Source code for 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>
回答1:
In either case you're seeing the output of index.php
. Here's why:
Scenario 1)
When you hit index.php
from the link in test.php
, it loads index.php
(with test.php
as the HTTP_REFERER
).
Scenario 2)
When you hit iframe.php
from the link in test.php
, it loads iframe.php
which internally loads index.php
in the <iframe>
tag (with iframe.php
as the HTTP_REFERER
).
回答2:
Unfortunately, no. The HTTP_REFERER value for a page shown inside an iframe will always be the parent page that contained the iframe.
HTTP_REFERER tends to be a little tricky to count on anyway. If you can avoid building any important logic around it, it's a good idea to do so.
I gather you're using php -- perhaps you could use session to store the last page visited when test.php loads? On test.php, you set $_SESSION['referringPage'] = 'test.php';
. Then on index.php, you read the value of $_SESSION['referringPage']
, and you get the same information regardless of whether the page was loaded within the iframe.
来源:https://stackoverflow.com/questions/1926211/php-http-referer-not-working-on-iframe