我想在 iframe 标签中显示网址的源代码。怎么办?例如,我有此代码。
<html>
<head>
<title></title>
</head>
<body>
<div>
<?php $content = @file_get_contents("http://stackoverflow.com"); ?>
</div>
</body>
如何在 iframe 中显示$content?
使用以下代码:编辑: iframe 版本..:
将此源另存为 getSource.php
<html>
<head>
<title></title>
</head>
<body>
<div>
<pre>
<?= htmlentities( @file_get_contents($_GET['url'])); ?>
</pre>
</div>
</body>
然后在不同页面上的某个地方使用您的 iframe,并使用 URL 变量将 src 添加到 getsource.php:
<iframe src="getsource.php?url=http://stackoverflow.com"></iframe>
这可能不安全,但我认为 htmlentities 可以防止 xss 攻击。
将此代码添加到main page
:
<html>
<head>
<title>Source Code</title>
</head>
<body>
<iframe src="phpscript.php">Your browser doesn't support iframes.</iframe>
</body>
把它放在phpscript.php
:
<pre>
<?php echo htmlentities( @file_get_contents("http://www.example.com/")); ?>
</pre>
然后,
您必须有一个单独的页面,其中包含iframe,其src
指向此页面。
不过,请问你为什么要使用iframe?似乎您可以在可滚动的"div"中显示它。