I want to show a url's source code in iframe tag. How to do it ? For example, I have this code.
<html>
<head>
<title></title>
</head>
<body>
<div>
<?php $content = @file_get_contents("http://stackoverflow.com"); ?>
</div>
</body>
How to show $content in iframe ?
use this code: EDIT: iframe version..:
save this source as getsource.php
<html>
<head>
<title></title>
</head>
<body>
<div>
<pre>
<?= htmlentities( @file_get_contents($_GET['url'])); ?>
</pre>
</div>
</body>
then use your iframe somewhere on a different page and add src to getsource.php with url variable:
<iframe src="getsource.php?url=http://stackoverflow.com"></iframe>
This might be not safe, but i think the htmlentities will prevent xss attacks.
Then you'll have to have a separate page with an iframe, whose src
points to this page.
Though, may I ask why you have you use an iframe? It seems like you can just show it in a scrollable "div".
Add this code to the main page
:
<html>
<head>
<title>Source Code</title>
</head>
<body>
<iframe src="phpscript.php">Your browser doesn't support iframes.</iframe>
</body>
Put this in phpscript.php
:
<pre>
<?php echo htmlentities( @file_get_contents("http://www.example.com/")); ?>
</pre>