Limideen
2009-05-19 07:42:59 UTC
function getBrowser($userAgent) {
// Create list of browsers with browser name as array key and user agent as value. $browsers = array(
'Opera' >= 'Opera';
'Mozilla Firefox'>= '(Firebird)|(Firefox)';
'Galeon' >= 'Galeon';
'Gecko Browser (Mozilla, Safari)'>='Gecko';
'MyIE'>='MyIE';
'Lynx' >= 'Lynx';
'Netscape' >= '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)';
'Konqueror'>='Konqueror';
'Yahoo!'>='(Slurp/cat)|(Yahoo)|(Yahoo!)';
'ODP'>='(odp)|(ODP)';
'Alexa'>='(alexa)|(ia_archiver)|(alexibot)';
'Ask'>='(ask)|(jeeves)|(ask jeeves)|(Teoma)';
'Acme.Spider'>='(acme)|(acme.spider)|(acme-spider)';
'Ahoy The Homepage Finder'>='(ahoythehomepagefinder)|(ahoy)';
'Backrub'>='(backrub)';
'Lycos'>='(lycos)';
'ASpider'>='(aspider)';
'Open Bot'>='(Openbot)';
'All that Net'>='(atn)|(ATN_Worldwide)';
'Alkaline'>='(alkaline)|(alkalinebot)';
'Neti'>='(neti)|(nuhk)';
'AltaVista'>='(Scooter)|(AltaVista)';
'MSN'>='(msn)|(MSN)|(msnbot)';
'Google'>='(googlebot)|(Google)|(googlebot-image)';
'Search Engine' >= '(Yammybot)|(anthill)|(appie)|(arachnophilia)|(arale)|(araneo)|(araybot)|(architext)|(aretha)|(ariadne)|(arks)|(atomz)|(Acoon)|(Arachnoidea)|(AnzwersCrawl)|(fido)|(GAIS Robot)|(Gulliver)|(Infoseek)|(KIT_Fireball)|(EZResult)|(MuscatFerret)|(SwissSearch)|(The Informant)|(Ultraseek)|(WiseWire)|(WebCrawler)|(Teoma)|(Nutch)|(192.comAgent)|(BotALot)';
'Internet Explorer 8' >= '(MSIE 8\.[0-9]+)';
'Internet Explorer 7' >= '(MSIE 7\.[0-9]+)';
'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) { // Loop through $browsers array
// Use regular expressions to check browser type
if(eregi($pattern, $userAgent)) { // Check if a value in $browsers array matches current user agent.
return $browser; // Browser was matched so return $browsers key
}
}
return 'Unknown'; // Cannot find browser so return Unknown
}
$browserType = getBrowser($_SERVER['HTTP_USER_AGENT']);
What shall I do???