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" />
Run Code Online (Sandbox Code Playgroud)
Is there a way I can set the favicon in PHP for a non HTML document?
大多数浏览器会默认在根目录中查找图标,如下所示:http : //example.com/favicon.ico。您可以将其用作图像的收藏夹图标。
如果您想为每个图像使用不同的图标,那是不可能的(浏览器没有为此提供任何机制)。有一个通过 HTTP 标头 ( RFC 5988 )设置网站图标的提议标准,但它仍然是一个草案,浏览器供应商尚未实施。