在 iframe html 标签中使用 php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20276613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:01:04  来源:igfitidea点击:

using php inside of iframe html tags

phphtmliframerequest-uri

提问by Firelight

I am trying to create a website that displays another website in an iframe.

我正在尝试创建一个在 iframe 中显示另一个网站的网站。

This is my code:

这是我的代码:

<html> 
<title>HTML with PHP</title>
<style>
body {
margin: 0px;
}
</style>
<body>
<?php
$page = $_GET['query'];
echo $page;
?>
<iframe align="center" width="100%" height="100%" src="<?=$page;?>" frameborder="yes" scrolling="yes" name="myIframe" id="myIframe"> </iframe>
</body>
</html>

When I open the php file off of my website (using a url website.com/file.php?query=https://www.google.com, and look in the inspector, I can see the page that the iframe loaded, but it just shows up as a blank page, not the . I have it up at http://www.test.fire-light.tk/web.php?query=url(replace url with any valid url). I am not sure why it shows the blank page.

当我从我的网站打开 php 文件时(使用 url website.com/file.php?query= https://www.google.com,并查看检查器,我可以看到 iframe 加载的页面,但它只是显示为一个空白页,而不是 。我在http://www.test.fire-light.tk/web.php?query=url(用任何有效的 url 替换 url)上有它 。我是不知道为什么它显示空白页。

回答by Arup Garai

Using Iframe you can call PHP file in HTML file . And write your PHP code in test.php Iframe code <iframe src="test.php"></iframe>

使用 Iframe,您可以在 HTML 文件中调用 PHP 文件。并在 test.php Iframe 代码中编写您的 PHP 代码<iframe src="test.php"></iframe>

回答by Sprunk

I think this:

我认为这:

<iframe align="center" width="100%" height="100%" src="<?=$page;?>" 
  frameborder="yes" scrolling="yes" name="myIframe" id="myIframe"> </iframe>

should be changed into:

应改为:

<iframe align="center" width="100%" height="100%" src="<? echo $page; ?>"  
  frameborder="yes" scrolling="yes" name="myIframe" id="myIframe"> </iframe>

回答by Grant

Try this instead:

试试这个:

<html> 
<title>HTML with PHP</title>
<style>
body {
margin: 0px;
}
</style>
<body>
<?php
$url = $_SERVER['REQUEST_URI'];
$parts = explode('?=', $url);
$page = $parts[1];
echo '<iframe align="center" width="100%" height="100%" src="$page" frameborder="yes" scrolling="yes" name="myIframe" id="myIframe"> </iframe>';
?>
</body>
</html>