Skip to content

Instantly share code, notes, and snippets.

@chawyehsu
Last active August 29, 2015 14:08
Show Gist options
  • Save chawyehsu/6b0fe7d0100df5727b75 to your computer and use it in GitHub Desktop.
Save chawyehsu/6b0fe7d0100df5727b75 to your computer and use it in GitHub Desktop.
[API] Get favcion of a site.
<?php
$url = @$_GET['url'];
if($url) {
$url = preg_replace('/http\:\/\//i', '', $url);
$url = 'http://' . $url;
$domain = parse_url($url);
$url = $domain['host'];
$dir = 'fcache';
$dfav = $dir . "/default.ico";
$fav = $dir . "/" . $url . ".ico";
header('Content-type: image/png');
$file = @file_get_contents($fav);
if($file) {
echo $file;
exit;
}
$file = @file_get_contents("http://$url/favicon.ico");
if($file) {
$f2 = $file;
echo $f2;
} else {
$w = @file_get_contents("http://$url/", 0, null, 0, 2000);
//@preg_match('|<link rel=\"shortcut icon\" href=\"(.*?)\".*>|ius',$w,$a);
@preg_match('|href=\"(.*?)\.ico\"|i', $w, $a);
if($a[1]) {
$a[1] .= '.ico';
$f = @file_get_contents($a[1]);
if($f) {
echo $f;
} else {
$u = 'http://' . $url . '/' . $a[1];
$f2 = @file_get_contents($u);
if($f2) {
echo $f2;
} else {
$f2 = @file_get_contents($dfav);
echo $f2;
}
}
} else {
$f2 = @file_get_contents($dfav);
echo $f2;
}
}
if($f2)
@file_put_contents($fav,$f2);
} else {
header("Content-Type:text/html;charset=utf-8");
echo 'This is a favcion api.';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment