从iframe内部获取父url变量


get parent url variable from inside an iframe

我有一个php网页,里面有一个iframe。例如:

php页面的urlhttp://www.ex.com/index.php?one=anumber

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body> <iframe id="34" class="ddd" src="two.php"></iframe>
</body>
</html>

那么,用什么php代码双关成两个php来从父url中获取变量one呢?

最简单的方法是将完整的查询字符串发送到two.php,就像一样

<iframe id="34" class="ddd" src="two.php?<?=$_SERVER['QUERY_STRING']?>"></iframe>

得到了…所以

这就是我所做的,我不懂php,但它可以

我创建了3个php文件,这就是他们的代码

index.php是相同的

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body> <iframe id="34" class="ddd" src="two.php"></iframe>
</body>
</html>

两位一位的HP是

<?php
   //Getting the parent window parameters
    $getURLVar = str_replace("?","",strrchr($_SERVER['HTTP_REFERER'],"?"));
   // refreshing the iframe with the variables at the end
    header("Location: 3.php?$getURLVar");
?>

在3.php中是

<?php 
$pageis888 = $_GET["one"];
?>

我知道有更好的解决方案,但这也有效:p