Get the browser you are using the client

This is the typical function that, some times, is necessary for finish view well our web.

Is true that HTML5 and the scripts how Modernizer that exists, simplifies the form to show the elements of the web in a browser but, some times is good know how discriminate by browser that user view us site, and actuate as the case (for example, for show a plug-in for download in case of a browser or an other).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function GetClientBrowser() {
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
  $browsers = array(
    'Opera'             => 'Opera',
    'Mozilla Firefox'   => '(Firebird)|(Firefox)',
    'Chrome'            => 'Chrome',
    'Safari'            => 'Safari',
    'Galeon'            => 'Galeon',
    'Mozilla'           => 'Gecko',
    'MyIE'              => 'MyIE',
    'Lynx'              => 'Lynx',
    'Netscape'          => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)',
    'Konqueror'         => 'Konqueror',
    'IE 7'              => 'MSIE 7',
    'IE 5'              => 'MSIE 5',
    'IE 6'              => 'MSIE 6',
    'IE 8'              => 'MSIE 8',
    'IE 9'              => 'MSIE 9',
    'Internet Explorer' => '(MSIE)'
  );
  foreach( $browsers as $browser => $pattern ){
    if ( strstr( $user_agent, $pattern ) )
      return $browser;
  }
  return 'Unknown';
}

Leave a Reply

Your email address will not be published. Required fields are marked *