PHP Library used to discover favicon from given URL

v2.0.0 2023-10-22 00:43 UTC


This library is based on Chris Shiflett work.

Here are the changes you can see in this version:

  • Cover more use case to find favicons
  • Composer support
  • Various technical changes and improvements
  • Unit tests



Use Composer by adding the following lines in your composer.json:

"require": {
    "arthurhoaro/favicon": "~2.0"

Basic Usage


$favicon = new \Favicon\Favicon();

echo $favicon->get('');
// Displays:
var_dump($favicon->get('http://nofavicon.tld', FaviconDLType::HOTLINK_URL));
// Returns false

You can avoid hotlinking by downloading the favicons:

$favicon = new \Favicon\Favicon();

// return the generated filename inside the cache folder
$favicon->get('', FaviconDLType::DL_FILE_PATH);
// return false

Or directly get the raw image as a binary string:

$favicon = new \Favicon\Favicon();

// return the binary string of the downloaded favicon
$favicon->get('', FaviconDLType::RAW_IMAGE);
// return false

Note: DL_FILE_PATH and RAW_IMAGE require the cache to be enabled.


You can setup cache settings:

$favicon = new Favicon();
$settings = array(
    // Cache directory
    'dir' => '/tmp/',
    // Cache timeout in seconds
    'timeout' => 86400,
    // Default image when no favicon is found
    'defaultico' => 'img/fav.ico'