I am making a simple script to check if a site has a favicon, and if so, to display it.
Here is the test script with a form:
http://www.metataggenerator.org/anal...viconcheck.php
As you can see, it is a work in progress...
There are three functions that I would like to do:
1.) Test to see if there is a favicon in the root directory, and if so, display it.
2.) Report if there is a favicon tag, and if so...
3.) Extract and display the favicon meta tag if it exists.
The first function is not working... I have tried a number of ways and cannot get it to properly report if there is no favicon in the root directory.
Here is the code:
PHP Code:<form action="faviconcheck.php" method="post">
<input type="text" name="url" value="http://www.metataggenerator.org" size="50" />
← Enter URL into this field and click "Favicon Check" (use http://)<br />
<input type="submit" value="Favicon Check" />
</form><br />
<p> </p>
<?php
echo '<b>1.) First Function: Test to see if favicon exists</b><br />';
function fileExists($path) {
if(@file_get_contents($path,0,NULL,0,1)){return 1;}else{ return 0;}
}
$url = $_POST['url'];
$path = "$url/favicon.ico";
if (fileExists($path) == 1) {
echo "<img src=\"$path\"> ← Favicon is in the root directory";
} else {
echo 'There is no favicon in the root directory';
}
echo '<hr />';
echo '<b>2.) Second Function: Extract the Favicon tag and display if exists</b><br />';
$page = file_get_contents("$url");
$explodefirst = explode('icon"',$page);
$headerisgone = $explodefirst[1];
$explodesecond = explode('>',$headerisgone);
$faviconlink = $explodesecond[0];
$explodefirst = explode('href="',$faviconlink);
$headerisgone = $explodefirst[1];
$explodesecond = explode('"',$headerisgone);
$faviconlink = $explodesecond[0];
echo "<img src=\"$faviconlink\"> ← Favicon.<br />";
echo $faviconlink;
echo '<hr />';
echo '<b>3.) Third Function: Report if there is a favicon tag.</b>';
echo '<br />';
$file = file_get_contents("$url");
if(!strpos($file, '<link rel="shortcut icon"')) {
echo '<font color="red">There is no favicon/shortcut tag.</font><br />';
} else {
echo 'There is a favicon/shortcut tag.<br />';
}
echo '<hr />';
?>


Reply With Quote

Bookmarks