Page 1 of 1

Browser Sniffing >> Insert Browser Specific HTML

Posted: Mon Sep 13, 2010 8:18 pm
by M4X
Hi, i'm trying to create a test that detects if a user is browsing with firefox. If the user is browsing with firefox i want the favicon to be directed to a animated gif. If the are not using firefox i want the favicon to directed to a standard non animated png favicon. I have researched around to try and find a solution using php but i'm very new to php and can't figure it out. if someone could give me a hand or point me in the right direction it would be much appreciated. My usual area is only HTML and CSS. Is php the best way to achieve this or should i be using another method eg. javascript. Thanks a lot! This is some code i have found and modified which doesn't work at all...

Code: Select all

<?php $browser = $_SERVER['HTTP_USER_AGENT']; ?>  

<?php if (strstr($browser, "Firefox")) { ?>  

<link rel="icon" href="address/favicon.gif" type="image/gif">

<?php }else{ ?>  

<link rel="icon" href="address/favicon.png" type="image/png">

<?php } ?>

Re: Browser Sniffing >> Insert Browser Specific HTML

Posted: Mon Sep 13, 2010 8:37 pm
by Jonah Bron
Try this:

Code: Select all

<?php
if (stripos($_SERVER['HTTP_USER_AGENT'], 'firefox') === false) {
?>
<link rel="icon" href="address/favicon.png" type="image/png">
<?php
} else {
?>
<link rel="icon" href="address/favicon.gif" type="image/gif">
<?php
}
?>

Re: Browser Sniffing >> Insert Browser Specific HTML

Posted: Mon Sep 13, 2010 8:55 pm
by requinix
stripos returns false, not -1.

Re: Browser Sniffing >> Insert Browser Specific HTML

Posted: Mon Sep 13, 2010 9:53 pm
by Jonah Bron
Oh yeah :oops:I got it mixed up with JavaScript's indexOf() :mrgreen:

Fixed.

Re: Browser Sniffing >> Insert Browser Specific HTML

Posted: Mon Sep 13, 2010 10:24 pm
by M4X
LEGENDS, works perfectly! Thanks so much!