在php的帮助下,iframe中的网页源代码

nir*_*nir 1 html php iframe

我想在iframe标签中显示网址的源代码.怎么做 ?例如,我有这个代码.

<html>
<head>
    <title></title>
</head>
<body>
    <div>
        <?php $content = @file_get_contents("http://stackoverflow.com"); ?>
    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

如何在iframe中显示$ content?

Mil*_*ike 5

使用此代码:编辑:iframe版本..:

将此源保存为getsource.php

<html>
<head>
    <title></title>
</head>
<body>
    <div>
        <pre>
        <?= htmlentities( @file_get_contents($_GET['url'])); ?>
        </pre>    
</div>
</body>
Run Code Online (Sandbox Code Playgroud)

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

<iframe src="getsource.php?url=http://stackoverflow.com"></iframe>
Run Code Online (Sandbox Code Playgroud)

这可能不安全,但我认为htmlentities会阻止xss攻击.