Detect browser and display

Want to detect the browser the user is using? This should help.

<?php
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
{
   if (
strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') )
   {
    
$browser = 'Netscape (Gecko/Netscape)';
   }
   else if (
strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') )
   {
    
$browser = 'Mozilla Firefox (Gecko/Firefox)';
   }
   else
   {
    
$browser = 'Mozilla (Gecko/Mozilla)';
   }
}
else if (
strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
{
   if (
strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
   {
    
$browser = 'Opera (MSIE/Opera/Compatible)';
   }
   else
   {
    
$browser = 'Internet Explorer (MSIE/Compatible)';
   }
}
else
{
  
$browser = 'Others browsers';
}

echo
$browser;
?>

block to refer IE users to Firefox

jillelaine - February 14, 2007 - 00:07

Thanks for the nice code! I'm not a big Internet Explorer fan...and I love Firefox. So I took the above code and changed it so it displays a block ONLY with Internet Explorer. With any other browser, no block appears. I put the block in the upper right sidebar.

The link to mozilla.com is not clickable in my block (though it is in the code in the post!)...I imagine that could be made clickable in the block too, but I don't know how.

I titled the block Yikes! You're using Internet Explorer!

<?php
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
{
   if (!
strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
   {
    
$browser = 'Internet Explorer (MSIE/Compatible)';
     echo
'Get Firefox at <a href="http://www.mozilla.com" title="http://www.mozilla.com" rel="nofollow">http://www.mozilla.com</a> Firefox is FREE. You\'ll love it.';
   }
}

?>

 
 

Drupal is a registered trademark of Dries Buytaert.