Use PHP to correct favicon.ico browser incompatibilities


Say you have a gif type favicon.ico and it works very well with Firefox but not with IE. Of course, you are not allowed to have two favicon.ico for your website. The only solution is to use PHP to provide server side scripting commands to display:

a. a GIF type favicon.ico for other browsers except IE.
b. display a plain favicon.ico for IE only.

Below is the PHP script which will be placed on the HEAD section of your dynamic website template:


<?php
$agent=$_SERVER['HTTP_USER_AGENT'];
if (preg_match("/\bMSIE\b/i",$agent))
{
//browser is IE
echo '<link rel="shortcut icon" href="http://www.php-developer.org/path to your favicon.ico to be used for IE only" />';
}
else
//other browsers not IE
{
echo '<link rel="shortcut icon" href="http://www.php-developer.org/path to gif style favicon.ico for other browsers" />';
}
?>

To implement this save two favicon.ico in your server, one for IE and one for other browsers. Edit the path above to reflect the favicon.ico location. Enjoy!



Related posts: