browser name // [1] => browser regexp // [2] => layout engine private static $browsers = array( // Bots 1000 => array('bot', '(?xi:crawler|robot|spider|bot|Slurp|Google Desktop|curl|wget| YahooSeeker|Python-urllib|htdig|Ask Jeeves|ia_archiver|sohu-search|bnf\.f| Yahoo-Blogs|B-l-i-t-z-B-O-T|httrack|boitho.com-dc|Dataparksearch|StackRambler| FyberSpider|ichiro|Larbin|ZyBorg|Arachmo|Cerberian Drtrs|Furl|Scrubby|libwww-perl| Mnogosearch|NG-search|Pompos|silk|Teomat)', self::BROWSER_ENGINE_BOT), // Opera browsers // Version < 10 http://www.opera.com/support/kb/view/570/ // Version >= 10 http://dev.opera.com/articles/view/opera-ua-string-changes/ 1 => array('Opera Mini', 'Opera Mini/([0-9.]+)', self::BROWSER_ENGINE_PRESTO), 9 => array('Opera', '(?:Opera/9\.[89][0-9].*Presto/([0-9.]+) Version/([0-9.]+)|Opera[/ ](?P[0-9.]+)(?:.*Presto/(?P[0-9.]+))?)', self::BROWSER_ENGINE_PRESTO), // MSIE browsers 10 => array('MyIE2', 'MSIE ([0-9.]+).*MyIE2', self::BROWSER_ENGINE_TRIDENT), 11 => array('AOL', 'MSIE ([0-9]+).*(?:AOL|America Online Browser)', self::BROWSER_ENGINE_TRIDENT), 12 => array('Avant Browser', 'MSIE ([0-9.]+).*Avant Browser', self::BROWSER_ENGINE_TRIDENT), 13 => array('Crazy Browser', 'MSIE ([0-9.]+).*Crazy Browser', self::BROWSER_ENGINE_TRIDENT), 13 => array('Maxthon', 'MSIE ([0-9.]+).*Maxthon', self::BROWSER_ENGINE_TRIDENT), 19 => array('Internet Explorer', 'MSIE ([0-9.]+)', self::BROWSER_ENGINE_TRIDENT), // Gecko browsers (a lot!) 20 => array('Iceape', 'Gecko/([0-9]+).*Iceape/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 21 => array('Camino', 'Gecko/([0-9]+).*Camino/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 22 => array('Epiphany', 'Gecko/([0-9]+).*Epiphany/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 23 => array('Firefox', 'Gecko(?:/([0-9]+))?.*(?:Firefox|BonEcho|GranParadiso|Firebird|Minefield)/([0-9abpre.]+)', self::BROWSER_ENGINE_GECKO), 24 => array('Galeon', 'Gecko/([0-9]+).*Galeon/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 25 => array('Iceweasel', 'Gecko/([0-9]+).*Iceweasel/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 26 => array('K-Meleon', 'Gecko/([0-9]+).*(?:K-Meleon|K-Ninja)/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 27 => array('Kazehakase', 'Gecko/([0-9]+).*Kazehakase/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 28 => array('Netscape', 'Gecko/([0-9]+).*Netscape[0-9]*/([0-9.]+)', self::BROWSER_ENGINE_GECKO), 29 => array('SeaMonkey', 'Gecko/([0-9]+).*SeMonkey/([0-9.]+)', self::BROWSER_ENGINE_GECKO), // We *don't* parse UA for Netscape < 6 versions, because it's too weird, and nobody care about it now 30 => array('Mozilla', 'Mozilla/5\.0.*rv:(?P[0-9.]+).*Gecko/(?P[0-9]+)', self::BROWSER_ENGINE_GECKO), // WebKit browsers 40 => array('NetNewsWire', 'AppleWebKit/([0-9.]+).*NetNewsWire/([0-9.]+)', self::BROWSER_ENGINE_WEBKIT), 41 => array('OmniWeb', 'AppleWebKit/([0-9.]+).*OmniWeb/v([0-9.]+)', self::BROWSER_ENGINE_WEBKIT), 42 => array('Shiira', 'AppleWebKit/([0-9.]+).*Shiira/([0-9.]+)', self::BROWSER_ENGINE_WEBKIT), 43 => array('Chrome', 'AppleWebKit/([0-9.]+).*Chrome/([0-9.]+)', self::BROWSER_ENGINE_WEBKIT), 59 => array('Safari', 'AppleWebKit/([0-9.]+).*Safari/([0-9.]+)', self::BROWSER_ENGINE_WEBKIT), // Other browsers 101 => array('Dillo', 'Dillo/([0-9.]+)', self::BROWSER_ENGINE_DILLO), 102 => array('Konqueror', 'Konqueror/([0-9.]+)', self::BROWSER_ENGINE_KHTML), 103 => array('Hv3', 'Mozilla/5\.1 (X11; U; Linux i686; en-US; rv:1\.8\.0\.3) Gecko/20060425 SUSE/1\.5\.0\.3-7 Firefox/1\.5\.0\.3', self::BROWSER_ENGINE_TKHTML), 104 => array('Amaya', 'amaya/([0-9.]+)', self::BROWSER_ENGINE_AMAYA), 105 => array('Lynx', 'Lynx/([0-9.]+)', self::BROWSER_ENGINE_TEXT), 106 => array('Links', 'Links \(([0-9.pre]+)', self::BROWSER_ENGINE_TEXT), 107 => array('ELinks', '(?i:ELinks)[ /(]+([0-9.]+)', self::BROWSER_ENGINE_TEXT), 108 => array('w3m', 'w3m/([0-9.]+)', self::BROWSER_ENGINE_TEXT), 0 => array('Unknow', '(?i:Gecko|WebKit|Opera|MSIE|KHTML|Browser)', self::BROWSER_ENGINE_UNKNOW), ); private static $systems = array( // Window systems 1 => array('Windows XP', '(?:Windows XP|Windows NT 5\.1)', self::PLATFORM_WINDOWS), 2 => array('Windows Vista', '(?:Windows Vista|Windows NT 6\.0)', self::PLATFORM_WINDOWS), 3 => array('Windows Server 2003', 'Windows NT 5\.2', self::PLATFORM_WINDOWS), 5 => array('Windows 2000', 'Windows NT 5\.0', self::PLATFORM_WINDOWS), 6 => array('Windows Me', 'Windows Me', self::PLATFORM_WINDOWS), 7 => array('Windows 95', 'Windows 95', self::PLATFORM_WINDOWS), 8 => array('Windows 98', 'Windows 98', self::PLATFORM_WINDOWS), // Mac 20 => array('Mac OS X', 'Mac OS X', self::PLATFORM_MAC), 21 => array('MacOS 9', '(?:Macintosh|Mac)', self::PLATFORM_MAC), // BSD 30 => array('OpenBSD', 'OpenBSD', self::PLATFORM_LINUX), 31 => array('FreeBSD', 'FreeBSD', self::PLATFORM_LINUX), // Consoles 40 => array('Console', '(?i:Wii|PSP|Playstation)', self::PLATFORM_CONSOLE), 41 => array('Mobile', '(?i:Maemo|Smartphone|Windows CE|iPhone|BlackBerry|Symbian|MIDP)', self::PLATFORM_MOBILE), // Linux 50 => array('Linux', 'Linux', self::PLATFORM_LINUX), ); private static $plugins = array( 1 => 'Flash', 2 => 'Java', 3 => 'QuickTime', 4 => 'RealPlayer', 5 => 'PDF', 6 => 'MPlayer', ); private static $rplugins = false; public static function extractInfos($ua) { $infos = array('id' => 0, 'os' => false, 'version' => 0, 'engine' => 0); foreach (self::$browsers as $id=>$properties) { if (preg_match('!'.$properties[1].'!i', $ua, $match)) { $infos['id'] = $id; if ($id == 1000) return $infos; if (isset($match['b'])) { $infos['version'] = $match['b']; } elseif (isset($match[2])) { $infos['version'] = $match[2]; } if (isset($match['e'])) { $infos['engine'] = $match['e']; } else { $infos['engine'] = $match[1]; } break; } } foreach (self::$systems as $id=>$properties) { if (preg_match('!'.$properties[1].'!i', $ua, $match)) { $infos['os'] = $id; break; } } if ($infos['id'] == 0) $infos['ua'] = $ua; return $infos; } public static function getBrowserName($id) { if (isset(self::$browsers[$id][0])) return self::$browsers[$id][0]; else return 'Unknown'; } public static function getBrowserEngine($id) { if (isset(self::$browsers[$id][2])) return self::$browsers[$id][2]; elseif ($id >= 1000) return self::BROWSER_ENGINE_BOT; else return self::BROWSER_ENGINE_UNKNOW; } public static function getOSName($id) { if (isset(self::$systems[$id][0])) return self::$systems[$id][0]; else return 'Unknown'; } public static function getOSPlatform($id) { if (isset(self::$systems[$id][2])) return self::$systems[$id][2]; else return self::PLATFORM_UNKNOW; } public static function extractLangs($langs_str) { $langs_str = explode(',', $langs_str); $langs = array(); foreach ($langs as $item) { if (preg_match('/;q=([0-9.,]+)/', $item, $match)) { $q = intval($match[1] * 10); $lang = str_replace($match[0], '', $item); } else { $q = 10; $lang = $item; } $lang = trim($lang); $lang = $lang[0] . $lang[1]; if (!in_array($lang, $langs)) $langs[$q] = $lang; } krsort($langs); return $langs; } public static function getPluginId($plugin) { if (!self::$rplugins) self::$rplugins = array_flip(self::$plugins); if (isset(self::$rplugins[$plugin])) return self::$rplugins[$plugin]; else return false; } } ?>