www.webdeveloper.com
Results 1 to 6 of 6

Thread: Favicon Check : Help!

Threaded View

  1. #1
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,096

    Favicon Check : Help!

    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" />
    &larr; Enter URL into this field and click &quot;Favicon Check&quot; (use http://)<br />
    <input type="submit" value="Favicon Check" />
    </form><br />
    <p>&nbsp;</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\"> &larr; 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\"> &larr; 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 />';


    ?>
    Last edited by donatello; 05-28-2011 at 06:48 AM. Reason: Ooops... forgot to post the PHP code... :) :P

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles