Saturday, 15 May 2010

php - file_exists, @get_headers, cURL and detecting a favicon -


After reading in different places, in this, I have the following work code that determines whether a given host eg There is a favicon located at /favicon.ico

  $ file = 'http://www.easyjet.com/favicon.ico'; $ File_headers = @get_headers ($ file); If ($ file_headers [0] == 'http / 1.0 200 is OK') {// favicon as an image on location "echo" and "IMG src = '". $ File "'& gt;"; } Other {// location Default Image Echo "& lt; img src = '". "Globe .JPG" "'' & gt;"; }  

When I know that there are better, more intensive ways to find a favicon file on the stack overflow, then I use my @get_headers I'm more worried. I have read, some suggest that curls can be useful, or I should establish a user agent.

Am I running in difficulty with this code in some cases which I do not think?

Personally I think get_headers is the best way in this case. First of all, it makes a major request, which weighs less for both you and the remote host (such as the remote host only provides the header and your server does not need to bring the image itself).

I do not really think that it will be the cause of any problem and I have not seen any issue due to the use of that function.


No comments:

Post a Comment