URLのソースコードをiframeタグで表示したい。どうやってするの ?たとえば、私はこのコードを持っています。
<html>
<head>
<title></title>
</head>
<body>
<div>
<?php $content = @file_get_contents("http://stackoverflow.com"); ?>
</div>
</body>
$content を iframe に表示するには?
このコードを使用してください: 編集: 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>
src
次に、このページを指すiframe を含む別のページを作成する必要があります。
では、なぜ iframe を使用しているのですか?スクロール可能な「div」で表示できるようです。