How do you tell using PHP whether a webpage is using iframes?
If i enter a site name in the text input,i want to know just one thing whether iframes has been used 开发者_如何学运维in a website or not. If yes it should return iframes found, otherwise iframes not found.
Seems easy enough:
<form method="post">
<input type="text" name="url" value="">
<input type="submit">
</form>
<?php
function usingIframes($url){
$html = file_get_contents($url);
$d = new DOMDocument();
$d->loadHTML("$html");
$iframe = $d->getElementByTagName('iframe');
return ($iframe->length>0);
}
if($_POST)
if(usingIframes($_POST['url']))
echo "Using Iframes";
else
echo "No frames";
Will return true if the url you've supplied has the iframe tag in it. False if not.
To do it with PHP you'll need to put something in the frame URL to let PHP know, like ?iframe-true. Assuming you're trying to make sure a site isn't included in an iframe without permission, you can do it by putting some Javascript in the page. Tons of ways to do it: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=javascript+break+out+of+iframe
Just search the content of the page for <IFRAME>
精彩评论