php - file_exists, @get_headers, cURL and detecting a favicon -
after reading in various places, including http://php.net/manual/en/function.file-exists.php, have following working code detects whether given host eg. http://example.com has favicon located @ /favicon.ico
$file = 'http://www.easyjet.com/favicon.ico'; $file_headers = @get_headers($file); if($file_headers[0] == 'http/1.0 200 ok') { //place favicon image on page echo "<img src ='" . $file . "'>"; } else { //place default image echo "<img src ='" . "globe.jpg" . "'>"; }
while know there better, more thorough ways seek favicon file on stackoverflow, more concerned use of @get_headers
. of have read suggests curl useful, or should set user agent.
am going run difficulty code in cases have not foreseen?
personaly think get_headers best way in case. first of all, performs head request, less load both , remote host(as remote host gives headers , server doesn't need fetch image itself).
i don't think cause trouble , haven't seen issues caused usage of function.
Comments
Post a Comment