DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Get_browser_
This function determines visitor browser.
function get_browser_($user_agent)
{
$browsers = array(
'Opera' => 'Opera',
'Mozilla Firefox'=> '(Firebird)|(Firefox)',
'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',
'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)',
'Internet Explorer 6' => '(MSIE 6\.[0-9]+)',
'Internet Explorer 5' => '(MSIE 5\.[0-9]+)',
'Internet Explorer 4' => '(MSIE 4\.[0-9]+)',
);
foreach($browsers as $browser=>$pattern)
{
if (eregi($pattern, $user_agent))
return $browser;
}
return 'Unknown';
}
For using:
echo get_browser_($_SERVER['HTTP_USER_AGENT']);





