借助php在Iframe中实现网页源代码

借助php在Iframe中实现网页源代码,php,html,iframe,Php,Html,Iframe,我想在iframe标记中显示url的源代码。怎么做? 例如,我有这个代码 <html> <head> <title></title> </head> <body> <div> <?php $content = @file_get_contents("http://stackoverflow.com"); ?> </div> </body>

我想在iframe标记中显示url的源代码。怎么做? 例如,我有这个代码

<html>
<head>
    <title></title>
</head>
<body>
    <div>
        <?php $content = @file_get_contents("http://stackoverflow.com"); ?>
    </div>
</body>
<html>
<head>
    <title></title>
</head>
<body>
    <div>
        <pre>
        <?= htmlentities( @file_get_contents($_GET['url'])); ?>
        </pre>    
</div>
</body>

如何在iframe中显示$content?

使用以下代码: 编辑:iframe版本..:

将此源代码另存为getsource.php


然后在不同页面的某个地方使用iframe,并使用url变量将src添加到getsource.php:

<html>
<head>
    <title>Source Code</title>
</head>
<body>
<iframe src="phpscript.php">Your browser doesn't support iframes.</iframe>
</body>

这可能不安全,但我认为htmlentities可以防止xss攻击。

使用以下代码: 编辑:iframe版本..:

将此源代码另存为getsource.php


然后在不同页面的某个地方使用iframe,并使用url变量将src添加到getsource.php:

<html>
<head>
    <title>Source Code</title>
</head>
<body>
<iframe src="phpscript.php">Your browser doesn't support iframes.</iframe>
</body>


这可能不安全,但我认为htmlentities可以防止xss攻击。

然后您必须有一个单独的带有iframe的页面,iframe的
src
指向此页面


但是,我可以问一下为什么要使用iframe吗?看起来你可以在一个可滚动的“div”中显示它。然后你必须有一个单独的带有iframe的页面,iframe的
src
指向这个页面


但是,我可以问一下为什么要使用iframe吗?您似乎可以将其显示在可滚动的“div”中。

将此代码添加到
主页面

<pre>
<?php echo htmlentities( @file_get_contents("http://www.example.com/")); ?>
</pre>

将此代码添加到
主页面

<pre>
<?php echo htmlentities( @file_get_contents("http://www.example.com/")); ?>
</pre>

@Abadis不太可能。。如果他没有使用htmlentities(),XSS攻击无论如何都是不可能的。(如果是的话,请说明如何处理。)这是因为源代码不是用PHP处理的,只是收集的+一个好的、直截了当的答案。你为什么希望它出现在iframe中?iframe不再被允许(HTML5)@50ndr33-iframe需要一个地址。将地址放在a.php上,并在a.php中编写给你的代码。对于xss攻击,我必须测试@阿巴迪斯不真的。。如果他没有使用htmlentities(),XSS攻击无论如何都是不可能的。(如果是的话,请说明如何处理。)这是因为源代码不是用PHP处理的,只是收集的+一个好的、直截了当的答案。你为什么希望它出现在iframe中?iframe不再被允许(HTML5)@50ndr33-iframe需要一个地址。将地址放在a.php上,并在a.php中编写给你的代码。对于xss攻击,我必须测试!!!我想在网页所有者单击带有突出显示代码的链接“查看代码”时向其显示网页的源代码。我想在网页所有者单击带有突出显示代码的链接“查看代码”时向其显示网页的源代码。为什么需要
?为什么需要