0

I need to be able to specify between IE 11 and Firefox in a PHP script. I have the following function. However, in IE it returns Mozilla. Is there another way to approach this to distinquish between Firefox and IE?

function browser() {
 $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
 // you can add different browsers with the same way ..
 if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
         $browser = 'chromium';
 elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
         $browser = 'chrome';
 elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
         $browser = 'safari';
 elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
         $browser = 'opera';
 elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
         $browser = 'msie';
 elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
         $browser = 'mozilla';

 preg_match('/('.$browser.')[ \/]([\w]+)/', $ua, $version);
 return array($browser,$version[2],'name'=>$browser,'version'=>$version[2]);
}

Thanks!

gibsonsg
  • 35
  • 2
  • 11

1 Answers1

0

Internet Explorer 11 didn't include an "MSIE" string, because they didn't want people to assume that it had the same problems as older versions of IE.

You could add lines like these:

elseif(preg_match('/(trident)[ \/]([\w.]+)/', $ua))
    $browser = 'msie';
elseif(preg_match('/(firefox)[ \/]([\w.]+)/', $ua))
    $browser = 'firefox';

Every web browser will contain the word "Mozilla" in its user agent string (it dates back to the Netscape era.)

libertyernie
  • 2,590
  • 1
  • 17
  • 13