2

I'm using PHP to display an image (dynamically returning a binary blob with a mime type of image/png for example) so that means I can't use the typical method for changing the favicon (link tags).

The HTML solution is this:

<link rel="shortcut icon" href="favicon.ico" />

Is there a way I can set the favicon in PHP for a non HTML document?

Spedwards
  • 4,167
  • 16
  • 49
  • 106
  • 2
    `I'm using PHP right now to display an image so that means absolutely no HTML is allowed` What does that mean? – John Conde Apr 25 '14 at 01:35
  • @JohnConde I don't know the best way of explaining it since I'm fairly new to PHP but I did ask a question about it a little while ago so you can understand what I mean. http://stackoverflow.com/questions/22727045/image-as-a-php-file – Spedwards Apr 25 '14 at 01:36

1 Answers1

6

Most browsers will default to looking for a favicon in the root directory like so: http://example.com/favicon.ico. You can use this for a favicon for your images.

If you want different favicons for each image, that's simply not possible (browsers provide no mechanism for this). There is a proposed standard for setting favicons via HTTP headers (RFC 5988) but it's still a draft and hasn't been implemented by browser vendors.

Community
  • 1
  • 1
Brandon
  • 16,382
  • 12
  • 55
  • 88
  • So if I were to put say, favicon-a in my root directory and then favicon-b in a subdirectory, would the pages in the subdirectory take favicon-a or favicon-b? Because that's how my website is set up right now. – Spedwards Apr 25 '14 at 01:59
  • No, the browser **only** looks in the root directory – Brandon Apr 25 '14 at 02:01