64 static protected $browsers = array(
67 'amigavoyager' =>
'AV',
84 'chromeframe' =>
'CF',
94 'mozilla firebird' =>
'FB',
100 'granparadiso' =>
'FF',
104 'thunderbird' =>
'TB',
108 'google earth' =>
'GE',
116 'microsoft internet explorer' =>
'IE',
117 'internet explorer' =>
'IE',
120 'kazehakase' =>
'KZ',
133 'ncsa mosaic' =>
'MC',
142 'nitro) opera' =>
'OP',
147 'applewebkit' =>
'SF',
153 static protected $browserType = array(
155 'gecko' => array(
'NS',
'PX',
'FF',
'FB',
'CA',
'GA',
'KM',
'MO',
'SM',
'CO',
'FE',
'KP',
'KZ',
'TB'),
156 'khtml' => array(
'KO'),
157 'webkit' => array(
'SF',
'CH',
'OW',
'AR',
'EP',
'FL',
'WO',
'AB',
'IR',
'CS',
'FD',
'HA',
'MI',
'GE',
'DF',
'BB',
'BP',
'TI',
'CF',
'RK',
'B2',
'NF'),
158 'opera' => array(
'OP'),
161 static protected $safariVersions = array(
162 '536.25' => array(
'6',
'0'),
163 '534.48' => array(
'5',
'1'),
164 '533.16' => array(
'5',
'0'),
165 '533.4' => array(
'4',
'1'),
166 '526.11.2' => array(
'4',
'0'),
167 '525.26' => array(
'3',
'2'),
168 '525.13' => array(
'3',
'1'),
169 '522.11' => array(
'3',
'0'),
170 '412' => array(
'2',
'0'),
171 '312' => array(
'1',
'3'),
172 '125' => array(
'1',
'2'),
173 '100' => array(
'1',
'1'),
174 '85' => array(
'1',
'0'),
175 '73' => array(
'0',
'9'),
176 '48' => array(
'0',
'8'),
179 static protected $omniWebVersions = array(
180 '622.15' => array(
'5',
'11'),
181 '622.10' => array(
'5',
'10'),
182 '622.8' => array(
'5',
'9'),
183 '622.3' => array(
'5',
'8'),
184 '621' => array(
'5',
'7'),
185 '613' => array(
'5',
'6'),
186 '607' => array(
'5',
'5'),
187 '563.34' => array(
'5',
'1'),
188 '558.36' => array(
'5',
'0'),
189 '496' => array(
'4',
'5'),
192 static protected $operatingSystems = array(
200 'CYGWIN_NT-6.2' =>
'WI8',
201 'Windows NT 6.2' =>
'WI8',
202 'Windows NT 6.3' =>
'WI8',
203 'Windows 8' =>
'WI8',
204 'CYGWIN_NT-6.1' =>
'WI7',
205 'Windows NT 6.1' =>
'WI7',
206 'Windows 7' =>
'WI7',
207 'CYGWIN_NT-6.0' =>
'WVI',
208 'Windows NT 6.0' =>
'WVI',
209 'Windows Vista' =>
'WVI',
210 'CYGWIN_NT-5.2' =>
'WS3',
211 'Windows NT 5.2' =>
'WS3',
212 'Windows Server 2003 / XP x64' =>
'WS3',
213 'CYGWIN_NT-5.1' =>
'WXP',
214 'Windows NT 5.1' =>
'WXP',
215 'Windows XP' =>
'WXP',
216 'CYGWIN_NT-5.0' =>
'W2K',
217 'Windows NT 5.0' =>
'W2K',
218 'Windows 2000' =>
'W2K',
219 'CYGWIN_NT-4.0' =>
'WNT',
220 'Windows NT 4.0' =>
'WNT',
222 'Windows NT' =>
'WNT',
223 'CYGWIN_ME-4.90' =>
'WME',
224 'Win 9x 4.90' =>
'WME',
225 'Windows ME' =>
'WME',
226 'CYGWIN_98-4.10' =>
'W98',
228 'Windows 98' =>
'W98',
229 'CYGWIN_95-4.0' =>
'W95',
232 'Windows 95' =>
'W95',
234 'Windows Phone OS' =>
'WPH',
237 'Windows Mobile' =>
'WMO',
239 'Windows CE' =>
'WCE',
245 'Macintosh' =>
'MAC',
246 'Power Macintosh' =>
'MAC',
247 'Mac_PowerPC' =>
'MAC',
250 'Mac PowerPC' =>
'MAC',
253 'Palm webOS' =>
'WOS',
257 'BlackBerry' =>
'BLB',
258 'RIM Tablet OS' =>
'QNX',
261 'Symbian OS' =>
'SYM',
262 'SymbianOS' =>
'SYM',
271 'DragonFly' =>
'DFB',
273 'Nintendo WiiU' =>
'WIU',
274 'Nintendo Wii' =>
'WII',
276 'Nintendo DSi' =>
'DSI',
277 'Nintendo DS' =>
'NDS',
278 'Nintendo 3DS' =>
'3DS',
279 'PlayStation Vita' =>
'PSV',
280 'PlayStation Portable' =>
'PSP',
281 'PlayStation 3' =>
'PS3',
292 static protected $osType = array(
293 'Windows' => array(
'WI8',
'WI7',
'WVI',
'WS3',
'WXP',
'W2K',
'WNT',
'WME',
'W98',
'W95'),
294 'Linux' => array(
'LIN'),
295 'Mac' => array(
'MAC'),
296 'iOS' => array(
'IPD',
'IPA',
'IPH'),
297 'Android' => array(
'AND'),
298 'Windows Mobile' => array(
'WPH',
'WMO',
'WCE'),
299 'Gaming Console' => array(
'WII',
'WIU',
'PS3',
'XBX'),
300 'Mobile Gaming Console' => array(
'PSP',
'PSV',
'NDS',
'DSI',
'3DS'),
301 'Unix' => array(
'SOS',
'AIX',
'HP-UX',
'BSD',
'NBS',
'OBS',
'DFB',
'SYL',
'IRI',
'T64'),
302 'Other Mobile' => array(
'MAE',
'WOS',
'POS',
'BLB',
'QNX',
'SYM',
'SBA'),
303 'Other' => array(
'VMS',
'OS2',
'BEOS',
'AMI')
305 static protected $browserIdToName;
306 static protected $browserIdToShortName;
307 static protected $operatingSystemsIdToName;
308 static protected $operatingSystemsIdToShortName;
309 static private $init =
false;
322 $userAgent = self::cleanupUserAgent($userAgent);
329 foreach (self::$operatingSystems as $key => $value) {
330 if (stristr($userAgent, $key) !==
false) {
331 $info[
'id'] = $value;
335 if (empty($info[
'id'])) {
338 $info[
'name'] = self::getOperatingSystemNameFromId($info[
'id']);
339 $info[
'short_name'] = self::getOperatingSystemShortNameFromId($info[
'id']);
342 static protected function cleanupUserAgent($userAgent)
345 return urldecode($userAgent);
363 $userAgent = self::cleanupUserAgent($userAgent);
369 'major_number' =>
'',
370 'minor_number' =>
'',
373 $browsers = self::$browsers;
375 unset($browsers[
'firefox']);
376 unset($browsers[
'mozilla']);
377 unset($browsers[
'safari']);
378 unset($browsers[
'applewebkit']);
379 $browsersPattern = str_replace(
')',
'\)', implode(
'|', array_keys($browsers)));
382 $userAgent = preg_replace(
'/[; ]Mozilla\/[0-9.]+ \([^)]+\)/',
'', $userAgent);
384 $userAgent = preg_replace(
'~^BlackBerry\d+/~',
'BlackBerry/', $userAgent);
385 if (preg_match_all(
"/($browsersPattern)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
386 || (strpos($userAgent,
'Shiira') ===
false && preg_match_all(
"/(firefox|thunderbird|safari)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results))
387 || preg_match_all(
"/(applewebkit)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $results)
388 || preg_match_all(
"/^(mozilla)\/([0-9]+)([\.0-9a-z-]+)?(?: \[[a-z]{2}\])? (?:\([^)]*\))$/i", $userAgent, $results)
389 || preg_match_all(
"/^(mozilla)\/[0-9]+(?:[\.0-9a-z-]+)?\s\(.* rv:([0-9]+)([.0-9a-z]+)\) gecko(\/[0-9]{8}|$)(?:.*)/i", $userAgent, $results)
390 || (strpos($userAgent,
'Nintendo 3DS') !==
false && preg_match_all(
"/^(mozilla).*version\/([0-9]+)([.0-9a-z]+)?/i", $userAgent, $results))
394 $info[
'id'] = self::$browsers[strtolower($results[1][0])];
396 if (strpos($userAgent,
'chromeframe') !==
false) {
397 $count = count($results[0]) - 1;
399 } elseif (($info[
'id'] ==
'IE' || $info[
'id'] ==
'LX') && (count($results[0]) > 1)) {
400 $count = count($results[0]) - 1;
401 $info[
'id'] = self::$browsers[strtolower($results[1][$count])];
404 if ($info[
'id'] ==
'MO' && $count == 0) {
405 if (stripos($userAgent,
'PlayStation') !==
false) {
408 if (strpos($userAgent,
'Nintendo 3DS') !==
false) {
410 } elseif (count($results) == 4) {
414 elseif (strpos($userAgent,
'BlackBerry') !==
false) {
416 } elseif (strpos($userAgent,
'RIM Tablet OS') !==
false) {
418 } elseif (strpos($userAgent,
'BB10') !==
false) {
420 } elseif (strpos($userAgent,
'Playstation Vita') !==
false) {
422 if (preg_match_all(
"/(silk)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
423 $results = $newResults;
424 $count = count($results[0]) - 1;
428 if (preg_match_all(
"/(version)[\/\sa-z(]*([0-9]+)([\.0-9a-z]+)?/i", $userAgent, $newResults)) {
429 $results = $newResults;
430 $count = count($results[0]) - 1;
433 $info[
'major_number'] = $results[2][$count];
436 preg_match(
'/([.\0-9]+)?([\.a-z0-9]+)?/i', $results[3][$count], $match);
437 if (isset($match[1])) {
439 $dot = strpos(substr($match[1], 1),
'.');
440 if ($dot !==
false) {
441 $info[
'minor_number'] = substr($match[1], 1, $dot);
443 $info[
'minor_number'] = substr($match[1], 1);
446 $info[
'minor_number'] =
'0';
448 $info[
'version'] = $info[
'major_number'] .
'.' . $info[
'minor_number'];
450 if ($info[
'id'] ==
'IE'
451 && (strncmp($userAgent,
'Mozilla/4.0', 11) == 0 || strncmp($userAgent,
'Mozilla/5.0', 11) == 0)
452 && preg_match(
'~ Trident/([0-9]+)\.[0-9]+~', $userAgent, $tridentVersion)
454 $info[
'major_number'] = $tridentVersion[1] + 4;
455 $info[
'minor_number'] =
'0';
456 $info[
'version'] = $info[
'major_number'] .
'.' . $info[
'minor_number'];
459 if ($info[
'id'] ==
'SF') {
460 foreach (self::$safariVersions as $buildVersion => $productVersion) {
461 if (version_compare($info[
'version'], $buildVersion) >= 0) {
462 $info[
'major_number'] = $productVersion[0];
463 $info[
'minor_number'] = $productVersion[1];
464 $info[
'version'] = $info[
'major_number'] .
'.' . $info[
'minor_number'];
470 if ($info[
'id'] ==
'OW') {
471 foreach (self::$omniWebVersions as $buildVersion => $productVersion) {
472 if (version_compare($info[
'version'], $buildVersion) >= 0) {
473 $info[
'major_number'] = $productVersion[0];
474 $info[
'minor_number'] = $productVersion[1];
475 $info[
'version'] = $info[
'major_number'] .
'.' . $info[
'minor_number'];
481 if ($info[
'id'] ==
'MO' && $info[
'version'] ==
'1.9') {
484 $info[
'name'] = self::getBrowserNameFromId($info[
'id']);
485 $info[
'short_name'] = self::getBrowserShortNameFromId($info[
'id']);
490 static protected function init()
497 self::$browserIdToName = array_map(
'ucwords', array_flip(self::$browsers));
498 self::$browserIdToName[
'AB'] =
'ABrowse';
499 self::$browserIdToName[
'AV'] =
'AmigaVoyager';
500 self::$browserIdToName[
'AW'] =
'Amiga AWeb';
501 self::$browserIdToName[
'BB'] =
'BlackBerry';
502 self::$browserIdToName[
'BP'] =
'PlayBook';
503 self::$browserIdToName[
'B2'] =
'BlackBerry';
504 self::$browserIdToName[
'BX'] =
'BrowseX';
505 self::$browserIdToName[
'CF'] =
'Chrome Frame';
506 self::$browserIdToName[
'CO'] =
'CometBird';
507 self::$browserIdToName[
'EL'] =
'ELinks';
508 self::$browserIdToName[
'FF'] =
'Firefox';
509 self::$browserIdToName[
'HJ'] =
'HotJava';
510 self::$browserIdToName[
'IB'] =
'IBrowse';
511 self::$browserIdToName[
'IC'] =
'iCab';
512 self::$browserIdToName[
'KM'] =
'K-Meleon';
513 self::$browserIdToName[
'MC'] =
'NCSA Mosaic';
514 self::$browserIdToName[
'NF'] =
'NetFront';
515 self::$browserIdToName[
'OW'] =
'OmniWeb';
516 self::$browserIdToName[
'SF'] =
'Safari';
517 self::$browserIdToName[
'SM'] =
'SeaMonkey';
518 self::$browserIdToName[
'WO'] =
'Palm webOS';
519 self::$browserIdToName[
'WP'] =
'WebPro';
520 self::$browserIdToShortName = self::$browserIdToName;
521 self::$browserIdToShortName[
'AW'] =
'AWeb';
522 self::$browserIdToShortName[
'FB'] =
'Firebird';
523 self::$browserIdToShortName[
'IE'] =
'IE';
524 self::$browserIdToShortName[
'MC'] =
'Mosaic';
525 self::$browserIdToShortName[
'BP'] =
'PlayBook';
526 self::$browserIdToShortName[
'WO'] =
'webOS';
528 $operatingSystemsIdToName = array(
531 'WME' =>
'Windows Me',
534 'NDS' =>
'Nintendo DS',
535 'WIU' =>
'Nintendo Wii U',
536 '3DS' =>
'Nintendo 3DS',
538 'W75' =>
'WinPhone 7.5',
539 'WP7' =>
'WinPhone 7',
540 'W65' =>
'WinMo 6.5',
541 'W61' =>
'WinMo 6.1',
543 self::$operatingSystemsIdToName = array_merge(array_flip(self::$operatingSystems), $operatingSystemsIdToName);
544 $operatingSystemsIdToShortName = array(
555 'WVI' =>
'Win Vista',
556 'WS3' =>
'Win S2003',
569 self::$operatingSystemsIdToShortName = array_merge(self::$operatingSystemsIdToName, $operatingSystemsIdToShortName);
571 static public function getBrowserNameFromId($browserId)
574 if (isset(self::$browserIdToName[$browserId])) {
575 return self::$browserIdToName[$browserId];
577 if(class_exists(
'DeviceDetector\\Parser\\Client\\Browser')) {
578 $browsers = DeviceDetector\Parser\Client\Browser::getAvailableBrowsers();
579 if( array_key_exists($browserId, $browsers)) {
580 return $browsers[$browserId];
585 static public function getBrowserShortNameFromId($browserId)
588 if (isset(self::$browserIdToShortName[$browserId])) {
589 return self::$browserIdToShortName[$browserId];
593 static public function getBrowserFamilyFromId($browserId)
596 $familyNameToUse =
'unknown';
597 foreach (self::$browserType as $familyName => $aBrowsers) {
598 if (in_array($browserId, $aBrowsers)) {
599 $familyNameToUse = $familyName;
603 return $familyNameToUse;
605 static public function getOperatingSystemNameFromId($osId)
608 if (isset(self::$operatingSystemsIdToName[$osId])) {
609 return self::$operatingSystemsIdToName[$osId];
611 if(class_exists(
'DeviceDetector\\Parser\\OperatingSystem')) {
612 if ($osId ==
'BOT') {
615 return DeviceDetector\Parser\OperatingSystem::getNameFromId($osId);
619 static public function getOperatingSystemShortNameFromId($osId)
622 if (isset(self::$operatingSystemsIdToShortName[$osId])) {
623 return self::$operatingSystemsIdToShortName[$osId];
627 static public function getOperatingSystemIdFromName($osName)
629 return isset(self::$operatingSystems[$osName]) ? self::$operatingSystems[$osName] :
false;
631 static public function getOperatingSystemFamilyFromId($osId)
634 foreach (self::$osType as $familyName => $aSystems) {
635 if (in_array($osId, $aSystems)) {
static getBrowser($userAgent)
static getOperatingSystem($userAgent)