Browser_Detection
[ class tree: Browser_Detection ] [ index: Browser_Detection ] [ all elements ]

Source for file BrowserDetection.php

Documentation is available at BrowserDetection.php

  1. <?php
  2.  
  3. /**
  4.  * Browser detection class file.
  5.  * This file contains everything required to use the BrowserDetection class.
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
  8.  * Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any
  9.  * later version (if any).
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12.  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13.  * details at: http://www.gnu.org/licenses/lgpl.html
  14.  *
  15.  * @package Browser_Detection
  16.  * @version 2.5.0
  17.  * @last-modified August 19, 2016
  18.  * @author Alexandre Valiquette
  19.  * @copyright Copyright (c) 2016, Wolfcast
  20.  * @link http://wolfcast.com/
  21.  */
  22.  
  23.  
  24. /**
  25.  * The BrowserDetection class facilitates the identification of the user's environment such as Web browser, version,
  26.  * platform or if it's a mobile device.
  27.  *
  28.  * Typical usage:
  29.  *
  30.  * $browser = new BrowserDetection();
  31.  * if ($browser->getName() == BrowserDetection::BROWSER_FIREFOX &&
  32.  *     $browser->compareVersions($browser->getVersion(), '5.0') >= 0) {
  33.  *     echo 'You are using FireFox version 5 or greater.';
  34.  * }
  35.  *
  36.  * The class is an updated version of Chris Schuld's Browser class version 1.9 which is unmaintained since August 20th,
  37.  * 2010. Chris' class was based on the original work from Gary White.
  38.  *
  39.  * Updates:
  40.  *
  41.  * 2016-08-19: Version 2.5.0
  42.  *  + Platform version and platform version name are now supported for Mac.
  43.  *  + Fixed platform version name for Android.
  44.  *
  45.  * 2016-08-02: Version 2.4.0
  46.  *  + Platform version and platform version name are now supported for Android.
  47.  *  + Added support for the Samsung Internet browser.
  48.  *  + Added support for the Vivaldi browser.
  49.  *  + Better support for legacy Windows versions.
  50.  *
  51.  * 2016-02-11: Version 2.3.0
  52.  *  + WARNING! Breaking change: public method getBrowser() is renamed to getName().
  53.  *  + WARNING! Breaking change: changed the compareVersions() return values to be more in line with other libraries.
  54.  *  + You can now get the exact platform version (name or version numbers) on which the browser is run on with
  55.  *    getPlatformVersion(). Only working with Windows operating systems at the moment.
  56.  *  + You can now determine if the browser is executed from a 64-bit platform with is64bitPlatform().
  57.  *  + Better detection of mobile platform for Googlebot.
  58.  *
  59.  * 2016-01-04: Version 2.2.0
  60.  *  + Added support for Microsoft Edge.
  61.  *
  62.  * 2014-12-30: Version 2.1.2
  63.  *  + Better detection of Opera.
  64.  *
  65.  * 2014-07-11: Version 2.1.1
  66.  *  + Better detection of mobile devices and platforms.
  67.  *
  68.  * 2014-06-04: Version 2.1.0
  69.  *  + Added support for IE 11+.
  70.  *
  71.  * 2013-05-27: Version 2.0.0 which is (almost) a complete rewrite based on Chris Schuld's Browser class version 1.9 plus
  72.  * changes below.
  73.  *  + Added support for Opera Mobile
  74.  *  + Added support for the Windows Phone (formerly Windows Mobile) platform
  75.  *  + Added support for BlackBerry Tablet OS and BlackBerry 10
  76.  *  + Added support for the Symbian platform
  77.  *  + Added support for Bingbot
  78.  *  + Added support for the Yahoo! Multimedia crawler
  79.  *  + Removed iPhone/iPad/iPod browsers since there are not browsers but platforms - test them with getPlatform()
  80.  *  + Removed support for Shiretoko (Firefox 3.5 alpha/beta) and MSN Browser
  81.  *  + Merged Nokia and Nokia S60
  82.  *  + Updated some deprecated browser names
  83.  *  + Many public methods are now protected
  84.  *  + Documentation updated
  85.  *
  86.  * 2010-07-04:
  87.  *  + Added detection of IE compatibility view - test with getIECompatibilityView()
  88.  *  + Added support for all (deprecated) Netscape versions
  89.  *  + Added support for Safari < 3.0
  90.  *  + Better Firefox version parsing
  91.  *  + Better Opera version parsing
  92.  *  + Better Mozilla detection
  93.  *
  94.  * @package Browser_Detection
  95.  * @version 2.5.0
  96.  * @last-modified August 19, 2016
  97.  * @author Alexandre Valiquette, Chris Schuld, Gary White
  98.  * @copyright Copyright (c) 2016, Wolfcast
  99.  * @license http://www.gnu.org/licenses/lgpl.html
  100.  * @link http://wolfcast.com/
  101.  * @link http://wolfcast.com/open-source/browser-detection/tutorial.php
  102.  * @link http://chrisschuld.com/
  103.  * @link http://www.apptools.com/phptools/browser/
  104.  */
  105. {
  106.  
  107.     /**#@+
  108.      * Constant for the name of the Web browser.
  109.      */
  110.     const BROWSER_AMAYA 'Amaya';
  111.     const BROWSER_ANDROID 'Android';
  112.     const BROWSER_BINGBOT 'Bingbot';
  113.     const BROWSER_BLACKBERRY 'BlackBerry';
  114.     const BROWSER_CHROME 'Chrome';
  115.     const BROWSER_EDGE 'Edge';
  116.     const BROWSER_FIREBIRD 'Firebird';
  117.     const BROWSER_FIREFOX 'Firefox';
  118.     const BROWSER_GALEON 'Galeon';
  119.     const BROWSER_GOOGLEBOT 'Googlebot';
  120.     const BROWSER_ICAB 'iCab';
  121.     const BROWSER_ICECAT 'GNU IceCat';
  122.     const BROWSER_ICEWEASEL 'GNU IceWeasel';
  123.     const BROWSER_IE 'Internet Explorer';
  124.     const BROWSER_IE_MOBILE 'Internet Explorer Mobile';
  125.     const BROWSER_KONQUEROR 'Konqueror';
  126.     const BROWSER_LYNX 'Lynx';
  127.     const BROWSER_MOZILLA 'Mozilla';
  128.     const BROWSER_MSNBOT 'MSNBot';
  129.     const BROWSER_MSNTV 'MSN TV';
  130.     const BROWSER_NETPOSITIVE 'NetPositive';
  131.     const BROWSER_NETSCAPE 'Netscape';
  132.     const BROWSER_NOKIA 'Nokia Browser';
  133.     const BROWSER_OMNIWEB 'OmniWeb';
  134.     const BROWSER_OPERA 'Opera';
  135.     const BROWSER_OPERA_MINI 'Opera Mini';
  136.     const BROWSER_OPERA_MOBILE 'Opera Mobile';
  137.     const BROWSER_PHOENIX 'Phoenix';
  138.     const BROWSER_SAFARI 'Safari';
  139.     const BROWSER_SAMSUNG 'Samsung Internet';
  140.     const BROWSER_SLURP 'Yahoo! Slurp';
  141.     const BROWSER_TABLET_OS 'BlackBerry Tablet OS';
  142.     const BROWSER_UNKNOWN 'unknown';
  143.     const BROWSER_VIVALDI 'Vivaldi';
  144.     const BROWSER_W3CVALIDATOR 'W3C Validator';
  145.     const BROWSER_YAHOO_MM 'Yahoo! Multimedia';
  146.     /**#@-*/
  147.  
  148.     /**#@+
  149.      * Constant for the name of the platform of the Web browser.
  150.      */
  151.     const PLATFORM_ANDROID 'Android';
  152.     const PLATFORM_BEOS 'BeOS';
  153.     const PLATFORM_BLACKBERRY 'BlackBerry';
  154.     const PLATFORM_FREEBSD 'FreeBSD';
  155.     const PLATFORM_IPAD 'iPad';
  156.     const PLATFORM_IPHONE 'iPhone';
  157.     const PLATFORM_IPOD 'iPod';
  158.     const PLATFORM_LINUX 'Linux';
  159.     const PLATFORM_MACINTOSH 'Macintosh';
  160.     const PLATFORM_NETBSD 'NetBSD';
  161.     const PLATFORM_NOKIA 'Nokia';
  162.     const PLATFORM_OPENBSD 'OpenBSD';
  163.     const PLATFORM_OPENSOLARIS 'OpenSolaris';
  164.     const PLATFORM_OS2 'OS/2';
  165.     const PLATFORM_SUNOS 'SunOS';
  166.     const PLATFORM_SYMBIAN 'Symbian';
  167.     const PLATFORM_UNKNOWN 'unknown';
  168.     const PLATFORM_VERSION_UNKNOWN 'unknown';
  169.     const PLATFORM_WINDOWS 'Windows';
  170.     const PLATFORM_WINDOWS_CE 'Windows CE';
  171.     const PLATFORM_WINDOWS_PHONE 'Windows Phone';
  172.     /**#@-*/
  173.  
  174.     /**
  175.      * Version unknown constant.
  176.      */
  177.     const VERSION_UNKNOWN 'unknown';
  178.  
  179.  
  180.     /**
  181.      * @var string 
  182.      * @access private
  183.      */
  184.     private $_agent = '';
  185.  
  186.     /**
  187.      * @var string 
  188.      * @access private
  189.      */
  190.     private $_aolVersion = '';
  191.  
  192.     /**
  193.      * @var string 
  194.      * @access private
  195.      */
  196.     private $_browserName = '';
  197.  
  198.     /**
  199.      * @var string 
  200.      * @access private
  201.      */
  202.     private $_compatibilityViewName = '';
  203.  
  204.     /**
  205.      * @var string 
  206.      * @access private
  207.      */
  208.     private $_compatibilityViewVer = '';
  209.  
  210.     /**
  211.      * @var boolean 
  212.      * @access private
  213.      */
  214.     private $_is64bit = false;
  215.  
  216.     /**
  217.      * @var boolean 
  218.      * @access private
  219.      */
  220.     private $_isAol = false;
  221.  
  222.     /**
  223.      * @var boolean 
  224.      * @access private
  225.      */
  226.     private $_isMobile = false;
  227.  
  228.     /**
  229.      * @var boolean 
  230.      * @access private
  231.      */
  232.     private $_isRobot = false;
  233.  
  234.     /**
  235.      * @var string 
  236.      * @access private
  237.      */
  238.     private $_platform = '';
  239.  
  240.     /**
  241.      * @var string 
  242.      * @access private
  243.      */
  244.     private $_platformVersion = '';
  245.  
  246.     /**
  247.      * @var string 
  248.      * @access private
  249.      */
  250.     private $_version = '';
  251.  
  252.  
  253.     //--- MAGIC METHODS ------------------------------------------------------------------------------------------------
  254.  
  255.  
  256.     /**
  257.      * BrowserDetection class constructor.
  258.      * @param string $useragent The user agent to work with. Leave empty for the current user agent (contained in
  259.      *  $_SERVER['HTTP_USER_AGENT']).
  260.      */
  261.     public function __construct($useragent '')
  262.     {
  263.         $this->setUserAgent($useragent);
  264.     }
  265.  
  266.     /**
  267.      * Determine how the class will react when it is treated like a string.
  268.      * @return string Returns an HTML formatted string with a summary of the browser informations.
  269.      */
  270.     public function __toString()
  271.     {
  272.         $result '';
  273.  
  274.         $values array();
  275.         $values[array('label' => 'User agent''value' => $this->getUserAgent());
  276.         $values[array('label' => 'Browser name''value' => $this->getName());
  277.         $values[array('label' => 'Browser version''value' => $this->getVersion());
  278.         $values[array('label' => 'Platform family''value' => $this->getPlatform());
  279.         $values[array('label' => 'Platform version''value' => $this->getPlatformVersion(true));
  280.         $values[array('label' => 'Platform version name''value' => $this->getPlatformVersion());
  281.         $values[array('label' => 'Platform is 64-bit''value' => $this->is64bitPlatform('true' 'false');
  282.         $values[array('label' => 'Is mobile''value' => $this->isMobile('true' 'false');
  283.         $values[array('label' => 'Is robot''value' => $this->isRobot('true' 'false');
  284.         $values[array('label' => 'IE is in compatibility view''value' => $this->isInIECompatibilityView('true' 'false');
  285.         $values[array('label' => 'Emulated IE version''value' => $this->isInIECompatibilityView($this->getIECompatibilityView('Not applicable');
  286.         $values[array('label' => 'Is Chrome Frame''value' => $this->isChromeFrame('true' 'false');
  287.         $values[array('label' => 'Is AOL optimized''value' => $this->isAol('true' 'false');
  288.         $values[array('label' => 'AOL version''value' => $this->isAol($this->getAolVersion('Not applicable');
  289.  
  290.         foreach ($values as $currVal{
  291.             $result .= '<strong>' htmlspecialchars($currVal['label']ENT_NOQUOTES':</strong> ' $currVal['value''<br />' PHP_EOL;
  292.         }
  293.  
  294.         return $result;
  295.     }
  296.  
  297.  
  298.     //--- PUBLIC MEMBERS -----------------------------------------------------------------------------------------------
  299.  
  300.  
  301.     /**
  302.      * Compare two version number strings.
  303.      * @param string $sourceVer The source version number.
  304.      * @param string $compareVer The version number to compare with the source version number.
  305.      * @return int Returns -1 if $sourceVer < $compareVer, 0 if $sourceVer == $compareVer or 1 if $sourceVer >
  306.      *  $compareVer.
  307.      */
  308.     public function compareVersions($sourceVer$compareVer)
  309.     {
  310.         $sourceVer explode('.'$sourceVer);
  311.         foreach ($sourceVer as $k => $v{
  312.             $sourceVer[$k$this->parseInt($v);
  313.         }
  314.  
  315.         $compareVer explode('.'$compareVer);
  316.         foreach ($compareVer as $k => $v{
  317.             $compareVer[$k$this->parseInt($v);
  318.         }
  319.  
  320.         if (count($sourceVer!= count($compareVer)) {
  321.             if (count($sourceVercount($compareVer)) {
  322.                 for ($i count($compareVer)$i count($sourceVer)$i++{
  323.                     $compareVer[$i0;
  324.                 }
  325.             else {
  326.                 for ($i count($sourceVer)$i count($compareVer)$i++{
  327.                     $sourceVer[$i0;
  328.                 }
  329.             }
  330.         }
  331.  
  332.         foreach ($sourceVer as $i => $srcVerPart{
  333.             if ($srcVerPart $compareVer[$i]{
  334.                 return 1;
  335.             else {
  336.                 if ($srcVerPart $compareVer[$i]{
  337.                     return -1;
  338.                 }
  339.             }
  340.         }
  341.  
  342.         return 0;
  343.     }
  344.  
  345.     /**
  346.      * Get the version of AOL (if any). AOL releases "optimized" Internet Explorer and Firefox versions. In the making
  347.      * they add their version number in the user agent string of these browsers.
  348.      * @return string Returns the version of AOL or an empty string if no AOL version was found.
  349.      */
  350.     public function getAolVersion()
  351.     {
  352.         return $this->_aolVersion;
  353.     }
  354.  
  355.     /**
  356.      * Get the name of the browser. All of the return values are class constants. You can compare them like this:
  357.      * $myBrowserInstance->getName() == BrowserDetection::BROWSER_FIREFOX.
  358.      * @return string Returns the name of the browser.
  359.      */
  360.     public function getName()
  361.     {
  362.         return $this->_browserName;
  363.     }
  364.  
  365.     /**
  366.      * Get the name and version of the browser emulated in the compatibility view mode (if any). Since Internet
  367.      * Explorer 8, IE can be put in compatibility mode to make websites that were created for older browsers, especially
  368.      * IE 6 and 7, look better in IE 8+ which renders web pages closer to the standards and thus differently from those
  369.      * older versions of IE.
  370.      * @param boolean $asArray Determines if the return value must be an array (true) or a string (false).
  371.      * @return mixed If a string was requested, the function returns the name and version of the browser emulated in the
  372.      *  compatibility view mode or an empty string if the browser is not in compatibility view mode. If an array was
  373.      *  requested, an array with the keys 'browser' and 'version' is returned.
  374.      */
  375.     public function getIECompatibilityView($asArray false)
  376.     {
  377.         if ($asArray{
  378.             return array('browser' => $this->_compatibilityViewName'version' => $this->_compatibilityViewVer);
  379.         else {
  380.             return trim($this->_compatibilityViewName . ' ' $this->_compatibilityViewVer);
  381.         }
  382.     }
  383.  
  384.     /**
  385.      * Get the name of the platform family on which the browser is run on (such as Windows, Apple, iPhone, etc.). All of
  386.      * the return values are class constants. You can compare them like this:
  387.      * $myBrowserInstance->getPlatform() == BrowserDetection::PLATFORM_ANDROID.
  388.      * @return string Returns the name of the platform or BrowserDetection::PLATFORM_UNKNOWN if unknown.
  389.      */
  390.     public function getPlatform()
  391.     {
  392.         return $this->_platform;
  393.     }
  394.  
  395.     /**
  396.      * Get the platform version on which the browser is run on. It can be returned as a string number like 'NT 6.3' or
  397.      * as a name like 'Windows 8.1'. When returning version string numbers for Windows NT OS families the number is
  398.      * prefixed by 'NT ' to differentiate from older Windows 3.x & 9x release. At the moment only the Windows and
  399.      * Android operating systems are supported.
  400.      * @param boolean $returnVersionNumbers Determines if the return value must be versions numbers as a string (true)
  401.      *  or the version name (false).
  402.      * @param boolean $returnServerFlavor Since some Windows NT versions have the same values, this flag determines if
  403.      *  the Server flavor is returned or not. For instance Windows 8.1 and Windows Server 2012 R2 both use version 6.3.
  404.      *  This parameter is only useful when testing for Windows.
  405.      * @return string Returns the version name/version numbers of the platform or the constant PLATFORM_VERSION_UNKNOWN
  406.      *  if unknown.
  407.      */
  408.     public function getPlatformVersion($returnVersionNumbers false$returnServerFlavor false)
  409.     {
  410.         if ($this->_platformVersion == self::PLATFORM_VERSION_UNKNOWN || $this->_platformVersion == ''{
  411.             return self::PLATFORM_VERSION_UNKNOWN;
  412.         }
  413.  
  414.         if ($returnVersionNumbers{
  415.             return $this->_platformVersion;
  416.         else {
  417.             switch ($this->getPlatform()) {
  418.                 case self::PLATFORM_WINDOWS:
  419.                     if (substr($this->_platformVersion03== 'NT '{
  420.                         return $this->windowsNTVerToStr(substr($this->_platformVersion3)$returnServerFlavor);
  421.                     else {
  422.                         return $this->windowsVerToStr($this->_platformVersion);
  423.                     }
  424.                 break;
  425.  
  426.                 case self::PLATFORM_MACINTOSH:
  427.                     return $this->macVerToStr($this->_platformVersion);
  428.                 break;
  429.  
  430.                 case self::PLATFORM_ANDROID:
  431.                     return $this->androidVerToStr($this->_platformVersion);
  432.                 break;
  433.  
  434.                 defaultreturn self::PLATFORM_VERSION_UNKNOWN;
  435.             }
  436.         }
  437.     }
  438.  
  439.     /**
  440.      * Get the user agent value used by the class to determine the browser details.
  441.      * @return string The user agent string.
  442.      */
  443.     public function getUserAgent()
  444.     {
  445.         return $this->_agent;
  446.     }
  447.  
  448.     /**
  449.      * Get the version of the browser.
  450.      * @return string Returns the version of the browser or BrowserDetection::VERSION_UNKNOWN if unknown.
  451.      */
  452.     public function getVersion()
  453.     {
  454.         return $this->_version;
  455.     }
  456.  
  457.     /**
  458.      * Determine if the browser is executed from a 64-bit platform. Keep in mind that not all platforms/browsers report
  459.      * this and the result may not always be accurate.
  460.      * @return boolean Returns true if the browser is executed from a 64-bit platform.
  461.      */
  462.     public function is64bitPlatform()
  463.     {
  464.         return $this->_is64bit;
  465.     }
  466.  
  467.     /**
  468.      * Determine if the browser is from AOL. AOL releases "optimized" Internet Explorer and Firefox versions. In the
  469.      * making they add their details in the user agent string of these browsers.
  470.      * @return boolean Returns true if the browser is from AOL, false otherwise.
  471.      */
  472.     public function isAol()
  473.     {
  474.         return $this->_isAol;
  475.     }
  476.  
  477.     /**
  478.      * Determine if the browser runs Google Chrome Frame (it's a plug-in designed for Internet Explorer 6+ based on the
  479.      * open-source Chromium project - it's like a Chrome browser within IE).
  480.      * @return boolean Returns true if the browser is using Google Chrome Frame, false otherwise.
  481.      */
  482.     public function isChromeFrame()
  483.     {
  484.         return stripos($this->_agent'chromeframe'!== false;
  485.     }
  486.  
  487.     /**
  488.      * Determine if the browser is in compatibility view or not. Since Internet Explorer 8, IE can be put in
  489.      * compatibility mode to make websites that were created for older browsers, especially IE 6 and 7, look better in
  490.      * IE 8+ which renders web pages closer to the standards and thus differently from those older versions of IE.
  491.      * @return boolean Returns true if the browser is in compatibility view, false otherwise.
  492.      */
  493.     public function isInIECompatibilityView()
  494.     {
  495.         return ($this->_compatibilityViewName != ''|| ($this->_compatibilityViewVer != '');
  496.     }
  497.  
  498.     /**
  499.      * Determine if the browser is from a mobile device or not.
  500.      * @return boolean Returns true if the browser is from a mobile device, false otherwise.
  501.      */
  502.     public function isMobile()
  503.     {
  504.         return $this->_isMobile;
  505.     }
  506.  
  507.     /**
  508.      * Determine if the browser is a robot (Googlebot, Bingbot, Yahoo! Slurp...) or not.
  509.      * @return boolean Returns true if the browser is a robot, false otherwise.
  510.      */
  511.     public function isRobot()
  512.     {
  513.         return $this->_isRobot;
  514.     }
  515.  
  516.     /**
  517.      * Set the user agent to use with the class.
  518.      * @param string $agentString The value of the user agent. If an empty string is sent (default),
  519.      *  $_SERVER['HTTP_USER_AGENT'] will be used.
  520.      */
  521.     public function setUserAgent($agentString '')
  522.     {
  523.         if (!is_string($agentString|| trim($agentString== ''{
  524.             if (array_key_exists('HTTP_USER_AGENT'$_SERVER&& is_string($_SERVER['HTTP_USER_AGENT'])) {
  525.                 $agentString $_SERVER['HTTP_USER_AGENT'];
  526.             else {
  527.                 $agentString '';
  528.             }
  529.         }
  530.  
  531.         $this->reset();
  532.         $this->_agent = $agentString;
  533.         $this->detect();
  534.     }
  535.  
  536.  
  537.     //--- PROTECTED MEMBERS --------------------------------------------------------------------------------------------
  538.  
  539.  
  540.     /**
  541.      * Convert the Android version numbers to the operating system name. For instance '1.6' returns 'Donut'.
  542.      * @access protected
  543.      * @param string $androidVer The Android version numbers as a string.
  544.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  545.      *  numbers.
  546.      */
  547.     protected function androidVerToStr($androidVer)
  548.     {
  549.         //https://en.wikipedia.org/wiki/Android_version_history
  550.  
  551.         if ($this->compareVersions($androidVer'7'>= && $this->compareVersions($androidVer'8'0{
  552.             return 'Nougat';
  553.         else if ($this->compareVersions($androidVer'6'>= && $this->compareVersions($androidVer'7'0{
  554.             return 'Marshmallow';
  555.         else if ($this->compareVersions($androidVer'5'>= && $this->compareVersions($androidVer'6'0{
  556.             return 'Lollipop';
  557.         else if ($this->compareVersions($androidVer'4.4'>= && $this->compareVersions($androidVer'5'0{
  558.             return 'KitKat';
  559.         else if ($this->compareVersions($androidVer'4.1'>= && $this->compareVersions($androidVer'4.4'0{
  560.             return 'Jelly Bean';
  561.         else if ($this->compareVersions($androidVer'4'>= && $this->compareVersions($androidVer'4.1'0{
  562.             return 'Ice Cream Sandwich';
  563.         else if ($this->compareVersions($androidVer'3'>= && $this->compareVersions($androidVer'4'0{
  564.             return 'Honeycomb';
  565.         else if ($this->compareVersions($androidVer'2.3'>= && $this->compareVersions($androidVer'3'0{
  566.             return 'Gingerbread';
  567.         else if ($this->compareVersions($androidVer'2.2'>= && $this->compareVersions($androidVer'2.3'0{
  568.             return 'Froyo';
  569.         else if ($this->compareVersions($androidVer'2'>= && $this->compareVersions($androidVer'2.2'0{
  570.             return 'Eclair';
  571.         else if ($this->compareVersions($androidVer'1.6'>= && $this->compareVersions($androidVer'2'0{
  572.             return 'Donut';
  573.         else if ($this->compareVersions($androidVer'1.5'>= && $this->compareVersions($androidVer'1.6'0{
  574.             return 'Cupcake';
  575.         else {
  576.             return self::PLATFORM_VERSION_UNKNOWN//Unknown/unnamed Android version
  577.         }
  578.     }
  579.  
  580.     /**
  581.      * Determine if the browser is the Amaya Web editor or not.
  582.      * @access protected
  583.      * @link http://www.w3.org/Amaya/
  584.      * @return boolean Returns true if the browser is Amaya, false otherwise.
  585.      */
  586.     protected function checkBrowserAmaya()
  587.     {
  588.         return $this->checkSimpleBrowserUA('amaya'$this->_agentself::BROWSER_AMAYA);
  589.     }
  590.  
  591.     /**
  592.      * Determine if the browser is the Android browser (based on the WebKit layout engine and coupled with Chrome's
  593.      * JavaScript engine) or not.
  594.      * @access protected
  595.      * @return boolean Returns true if the browser is the Android browser, false otherwise.
  596.      */
  597.     protected function checkBrowserAndroid()
  598.     {
  599.         //Android don't use the standard "Android/1.0", it uses "Android 1.0;" instead
  600.         return $this->checkSimpleBrowserUA('Android'$this->_agentself::BROWSER_ANDROIDtrue);
  601.     }
  602.  
  603.     /**
  604.      * Determine if the browser is the Bingbot crawler or not.
  605.      * @access protected
  606.      * @link http://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0
  607.      * @return boolean Returns true if the browser is Bingbot, false otherwise.
  608.      */
  609.     protected function checkBrowserBingbot()
  610.     {
  611.         return $this->checkSimpleBrowserUA('bingbot'$this->_agentself::BROWSER_BINGBOTfalsetrue);
  612.     }
  613.  
  614.     /**
  615.      * Determine if the browser is the BlackBerry browser or not.
  616.      * @access protected
  617.      * @link http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/How-to-detect-the-BlackBerry-Browser/ta-p/559862
  618.      * @return boolean Returns true if the browser is the BlackBerry browser, false otherwise.
  619.      */
  620.     protected function checkBrowserBlackBerry()
  621.     {
  622.         $found false;
  623.  
  624.         //Tablet OS check
  625.         if ($this->checkSimpleBrowserUA('RIM Tablet OS'$this->_agentself::BROWSER_TABLET_OStrue)) {
  626.             return true;
  627.         }
  628.  
  629.         //Version 6, 7 & 10 check (versions 8 & 9 does not exists)
  630.         if ($this->checkBrowserUAWithVersion(array('BlackBerry''BB10')$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  631.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  632.                 $found true;
  633.             else {
  634.                 return true;
  635.             }
  636.         }
  637.  
  638.         //Version 4.2 to 5.0 check
  639.         if ($this->checkSimpleBrowserUA('BlackBerry'$this->_agentself::BROWSER_BLACKBERRYtrue)) {
  640.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  641.                 $found true;
  642.             else {
  643.                 return true;
  644.             }
  645.         }
  646.  
  647.         return $found;
  648.     }
  649.  
  650.     /**
  651.      * Determine if the browser is Chrome or not.
  652.      * @access protected
  653.      * @link http://www.google.com/chrome/
  654.      * @return boolean Returns true if the browser is Chrome, false otherwise.
  655.      */
  656.     protected function checkBrowserChrome()
  657.     {
  658.         return $this->checkSimpleBrowserUA('Chrome'$this->_agentself::BROWSER_CHROME);
  659.     }
  660.  
  661.     /**
  662.      * Determine if the browser is Edge or not.
  663.      * @access protected
  664.      * @return boolean Returns true if the browser is Edge, false otherwise.
  665.      */
  666.     protected function checkBrowserEdge()
  667.     {
  668.         return $this->checkSimpleBrowserUA('Edge'$this->_agentself::BROWSER_EDGE);
  669.     }
  670.  
  671.     /**
  672.      * Determine if the browser is Firebird or not. Firebird was the name of Firefox from version 0.6 to 0.7.1.
  673.      * @access protected
  674.      * @return boolean Returns true if the browser is Firebird, false otherwise.
  675.      */
  676.     protected function checkBrowserFirebird()
  677.     {
  678.         return $this->checkSimpleBrowserUA('Firebird'$this->_agentself::BROWSER_FIREBIRD);
  679.     }
  680.  
  681.     /**
  682.      * Determine if the browser is Firefox or not.
  683.      * @access protected
  684.      * @link http://www.mozilla.org/en-US/firefox/new/
  685.      * @return boolean Returns true if the browser is Firefox, false otherwise.
  686.      */
  687.     protected function checkBrowserFirefox()
  688.     {
  689.         //Safari heavily matches with Firefox, ensure that Safari is filtered out...
  690.         if (preg_match('/.*Firefox[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches&&
  691.                 stripos($this->_agent'Safari'=== false{
  692.             $this->setBrowser(self::BROWSER_FIREFOX);
  693.             $this->setVersion($matches[1]);
  694.             $this->setMobile(false);
  695.             $this->setRobot(false);
  696.  
  697.             return true;
  698.         }
  699.  
  700.         return false;
  701.     }
  702.  
  703.     /**
  704.      * Determine if the browser is Galeon or not. The browser was discontinued on September 27, 2008.
  705.      * @access protected
  706.      * @link http://en.wikipedia.org/wiki/Galeon
  707.      * @return boolean Returns true if the browser is Galeon, false otherwise.
  708.      */
  709.     protected function checkBrowserGaleon()
  710.     {
  711.         return $this->checkSimpleBrowserUA('Galeon'$this->_agentself::BROWSER_GALEON);
  712.     }
  713.  
  714.     /**
  715.      * Determine if the browser is the Googlebot crawler or not.
  716.      * @access protected
  717.      * @return boolean Returns true if the browser is Googlebot, false otherwise.
  718.      */
  719.     protected function checkBrowserGooglebot()
  720.     {
  721.         if ($this->checkSimpleBrowserUA('Googlebot'$this->_agentself::BROWSER_GOOGLEBOTfalsetrue)) {
  722.             if (strpos(strtolower($this->_agent)'googlebot-mobile'!== false{
  723.                 $this->setMobile(true);
  724.             }
  725.  
  726.             return true;
  727.         }
  728.  
  729.         return false;
  730.     }
  731.  
  732.     /**
  733.      * Determine if the browser is iCab or not.
  734.      * @access protected
  735.      * @link http://www.icab.de/
  736.      * @return boolean Returns true if the browser is iCab, false otherwise.
  737.      */
  738.     protected function checkBrowserIcab()
  739.     {
  740.         //Some (early) iCab versions don't use the standard "iCab/1.0", they uses "iCab 1.0;" instead
  741.         return $this->checkSimpleBrowserUA('iCab'$this->_agentself::BROWSER_ICAB);
  742.     }
  743.  
  744.     /**
  745.      * Determine if the browser is GNU IceCat (formerly known as GNU IceWeasel) or not.
  746.      * @access protected
  747.      * @link http://www.gnu.org/software/gnuzilla/
  748.      * @return boolean Returns true if the browser is GNU IceCat, false otherwise.
  749.      */
  750.     protected function checkBrowserIceCat()
  751.     {
  752.         return $this->checkSimpleBrowserUA('IceCat'$this->_agentself::BROWSER_ICECAT);
  753.     }
  754.  
  755.     /**
  756.      * Determine if the browser is GNU IceWeasel (now know as GNU IceCat) or not.
  757.      * @access protected
  758.      * @see checkBrowserIceCat()
  759.      * @return boolean Returns true if the browser is GNU IceWeasel, false otherwise.
  760.      */
  761.     protected function checkBrowserIceWeasel()
  762.     {
  763.         return $this->checkSimpleBrowserUA('Iceweasel'$this->_agentself::BROWSER_ICEWEASEL);
  764.     }
  765.  
  766.     /**
  767.      * Determine if the browser is Internet Explorer or not.
  768.      * @access protected
  769.      * @link http://www.microsoft.com/ie/
  770.      * @link http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  771.      * @return boolean Returns true if the browser is Internet Explorer, false otherwise.
  772.      */
  773.     protected function checkBrowserInternetExplorer()
  774.     {
  775.         //Test for Internet Explorer Mobile (formerly Pocket Internet Explorer)
  776.         if ($this->checkSimpleBrowserUA(array('IEMobile''MSPIE')$this->_agentself::BROWSER_IE_MOBILEtrue)) {
  777.             return true;
  778.         }
  779.  
  780.         //Several browsers uses IE compatibility UAs filter these browsers out (but after testing for IE Mobile)
  781.         if (stripos($this->_agent'Opera'!== false ||
  782.                 stripos($this->_agent'BlackBerry'!== false ||
  783.                 stripos($this->_agent'Nokia'!== false{
  784.             return false;
  785.         }
  786.  
  787.         //Test for Internet Explorer 1
  788.         if ($this->checkSimpleBrowserUA('Microsoft Internet Explorer'$this->_agentself::BROWSER_IE)) {
  789.             if ($this->getVersion(== self::VERSION_UNKNOWN{
  790.                 if (preg_match('/308|425|426|474|0b1/i'$this->_agent)) {
  791.                     $this->setVersion('1.5');
  792.                 else {
  793.                     $this->setVersion('1.0');
  794.                 }
  795.             }
  796.             return true;
  797.         }
  798.  
  799.         //Test for Internet Explorer 2+
  800.         if (stripos($this->_agent'MSIE'!== false || stripos($this->_agent'Trident'!== false{
  801.             $version '';
  802.  
  803.             if (stripos($this->_agent'Trident'!== false{
  804.                 //Test for Internet Explorer 11+ (check the rv: string)
  805.                 if (stripos($this->_agent'rv:'!== false{
  806.                     if ($this->checkSimpleBrowserUA('Trident'$this->_agentself::BROWSER_IEfalsefalse'rv:')) {
  807.                         return true;
  808.                     }
  809.                 else {
  810.                     //Test for Internet Explorer 8, 9 & 10 (check the Trident string)
  811.                     if (preg_match('/Trident\/([\d]+)/i'$this->_agent$foundVersion)) {
  812.                         //Trident started with version 4.0 on IE 8
  813.                         $verFromTrident $this->parseInt($foundVersion[1]4;
  814.                         if ($verFromTrident >= 8{
  815.                             $version $verFromTrident '.0';
  816.                         }
  817.                     }
  818.                 }
  819.  
  820.                 //If we have the IE version from Trident, we can check for the compatibility view mode
  821.                 if ($version != ''{
  822.                     $emulatedVer '';
  823.                     preg_match_all('/MSIE\s*([^\s;$]+)/i'$this->_agent$foundVersions);
  824.                     foreach ($foundVersions[1as $currVer{
  825.                         //Keep the lowest MSIE version for the emulated version (in compatibility view mode)
  826.                         if ($emulatedVer == '' || $this->compareVersions($emulatedVer$currVer== 1{
  827.                             $emulatedVer $currVer;
  828.                         }
  829.                     }
  830.                     //Set the compatibility view mode if $version != $emulatedVer
  831.                     if ($this->compareVersions($version$emulatedVer!= 0{
  832.                         $this->_compatibilityViewName = self::BROWSER_IE;
  833.                         $this->_compatibilityViewVer = $this->cleanVersion($emulatedVer);
  834.                     }
  835.                 }
  836.             }
  837.  
  838.             //Test for Internet Explorer 2-7 versions if needed
  839.             if ($version == ''{
  840.                 preg_match_all('/MSIE\s+([^\s;$]+)/i'$this->_agent$foundVersions);
  841.                 foreach ($foundVersions[1as $currVer{
  842.                     //Keep the highest MSIE version
  843.                     if ($version == '' || $this->compareVersions($version$currVer== -1{
  844.                         $version $currVer;
  845.                     }
  846.                 }
  847.             }
  848.  
  849.             $this->setBrowser(self::BROWSER_IE);
  850.             $this->setVersion($version);
  851.             $this->setMobile(false);
  852.             $this->setRobot(false);
  853.  
  854.             return true;
  855.         }
  856.  
  857.         return false;
  858.     }
  859.  
  860.     /**
  861.      * Determine if the browser is Konqueror or not.
  862.      * @access protected
  863.      * @link http://www.konqueror.org/
  864.      * @return boolean Returns true if the browser is Konqueror, false otherwise.
  865.      */
  866.     protected function checkBrowserKonqueror()
  867.     {
  868.         return $this->checkSimpleBrowserUA('Konqueror'$this->_agentself::BROWSER_KONQUEROR);
  869.     }
  870.  
  871.     /**
  872.      * Determine if the browser is Lynx or not. It is the oldest web browser currently in general use and development.
  873.      * It is a text-based only Web browser.
  874.      * @access protected
  875.      * @link http://en.wikipedia.org/wiki/Lynx
  876.      * @return boolean Returns true if the browser is Lynx, false otherwise.
  877.      */
  878.     protected function checkBrowserLynx()
  879.     {
  880.         return $this->checkSimpleBrowserUA('Lynx'$this->_agentself::BROWSER_LYNX);
  881.     }
  882.  
  883.     /**
  884.      * Determine if the browser is Mozilla or not.
  885.      * @access protected
  886.      * @return boolean Returns true if the browser is Mozilla, false otherwise.
  887.      */
  888.     protected function checkBrowserMozilla()
  889.     {
  890.         return $this->checkSimpleBrowserUA('Mozilla'$this->_agentself::BROWSER_MOZILLAfalsefalse'rv:');
  891.     }
  892.  
  893.     /**
  894.      * Determine if the browser is the MSNBot crawler or not. In October 2010 it was replaced by the Bingbot robot.
  895.      * @access protected
  896.      * @see checkBrowserBingbot()
  897.      * @return boolean Returns true if the browser is MSNBot, false otherwise.
  898.      */
  899.     protected function checkBrowserMsnBot()
  900.     {
  901.         return $this->checkSimpleBrowserUA('msnbot'$this->_agentself::BROWSER_MSNBOTfalsetrue);
  902.     }
  903.  
  904.     /**
  905.      * Determine if the browser is MSN TV (formerly WebTV) or not.
  906.      * @access protected
  907.      * @link http://en.wikipedia.org/wiki/MSN_TV
  908.      * @return boolean Returns true if the browser is WebTv, false otherwise.
  909.      */
  910.     protected function checkBrowserMsnTv()
  911.     {
  912.         return $this->checkSimpleBrowserUA('webtv'$this->_agentself::BROWSER_MSNTV);
  913.     }
  914.  
  915.     /**
  916.      * Determine if the browser is NetPositive or not. The browser is discontinued since November 2001.
  917.      * @access protected
  918.      * @link http://en.wikipedia.org/wiki/NetPositive
  919.      * @return boolean Returns true if the browser is NetPositive, false otherwise.
  920.      */
  921.     protected function checkBrowserNetPositive()
  922.     {
  923.         return $this->checkSimpleBrowserUA('NetPositive'$this->_agentself::BROWSER_NETPOSITIVE);
  924.     }
  925.  
  926.     /**
  927.      * Determine if the browser is Netscape or not. Official support for this browser ended on March 1st, 2008.
  928.      * @access protected
  929.      * @link http://en.wikipedia.org/wiki/Netscape
  930.      * @return boolean Returns true if the browser is Netscape, false otherwise.
  931.      */
  932.     protected function checkBrowserNetscape()
  933.     {
  934.         //BlackBerry & Nokia UAs can conflict with Netscape UAs
  935.         if (stripos($this->_agent'BlackBerry'!== false || stripos($this->_agent'Nokia'!== false{
  936.             return false;
  937.         }
  938.  
  939.         //Netscape v6 to v9 check
  940.         if ($this->checkSimpleBrowserUA(array('Netscape''Navigator''Netscape6')$this->_agentself::BROWSER_NETSCAPE)) {
  941.             return true;
  942.         }
  943.  
  944.         //Netscape v1-4 (v5 don't exists)
  945.         $found false;
  946.         if (stripos($this->_agent'Mozilla'!== false && stripos($this->_agent'rv:'=== false{
  947.             $version '';
  948.             $verParts explode('/'stristr($this->_agent'Mozilla'));
  949.             if (count($verParts1{
  950.                 $verParts explode(' '$verParts[1]);
  951.                 $verParts explode('.'$verParts[0]);
  952.  
  953.                 $majorVer $this->parseInt($verParts[0]);
  954.                 if ($majorVer && $majorVer 5{
  955.                     $version implode('.'$verParts);
  956.                     $found true;
  957.  
  958.                     if (strtolower(substr($version-4)) == '-sgi'{
  959.                         $version substr($version0-4);
  960.                     else {
  961.                         if (strtolower(substr($version-4)) == 'gold'{
  962.                             $version substr($version0-4' Gold'//Doubles spaces (if any) will be normalized by setVersion()
  963.                         }
  964.                     }
  965.                 }
  966.             }
  967.         }
  968.  
  969.         if ($found{
  970.             $this->setBrowser(self::BROWSER_NETSCAPE);
  971.             $this->setVersion($version);
  972.             $this->setMobile(false);
  973.             $this->setRobot(false);
  974.         }
  975.  
  976.         return $found;
  977.     }
  978.  
  979.     /**
  980.      * Determine if the browser is a Nokia browser or not.
  981.      * @access protected
  982.      * @link http://www.developer.nokia.com/Community/Wiki/User-Agent_headers_for_Nokia_devices
  983.      * @return boolean Returns true if the browser is a Nokia browser, false otherwise.
  984.      */
  985.     protected function checkBrowserNokia()
  986.     {
  987.         if (stripos($this->_agent'Nokia5800'!== false || stripos($this->_agent'Nokia5530'!== false || stripos($this->_agent'Nokia5230'!== false{
  988.             $this->setBrowser(self::BROWSER_NOKIA);
  989.             $this->setVersion('7.0');
  990.             $this->setMobile(true);
  991.             $this->setRobot(false);
  992.  
  993.             return true;
  994.         }
  995.  
  996.         if ($this->checkSimpleBrowserUA(array('NokiaBrowser''BrowserNG''Series60''S60''S40OviBrowser')$this->_agentself::BROWSER_NOKIAtrue)) {
  997.             return true;
  998.         }
  999.  
  1000.         return false;
  1001.     }
  1002.  
  1003.     /**
  1004.      * Determine if the browser is OmniWeb or not.
  1005.      * @access protected
  1006.      * @link http://www.omnigroup.com/products/omniweb/
  1007.      * @return boolean Returns true if the browser is OmniWeb, false otherwise.
  1008.      */
  1009.     protected function checkBrowserOmniWeb()
  1010.     {
  1011.         if ($this->checkSimpleBrowserUA('OmniWeb'$this->_agentself::BROWSER_OMNIWEB)) {
  1012.             //Some versions of OmniWeb prefix the version number with "v"
  1013.             if ($this->getVersion(!= self::VERSION_UNKNOWN && strtolower(substr($this->getVersion()01)) == 'v'{
  1014.                 $this->setVersion(substr($this->getVersion()1));
  1015.             }
  1016.             return true;
  1017.         }
  1018.  
  1019.         return false;
  1020.     }
  1021.  
  1022.     /**
  1023.      * Determine if the browser is Opera or not.
  1024.      * @access protected
  1025.      * @link http://www.opera.com/
  1026.      * @link http://www.opera.com/mini/
  1027.      * @link http://www.opera.com/mobile/
  1028.      * @link http://my.opera.com/community/openweb/idopera/
  1029.      * @return boolean Returns true if the browser is Opera, false otherwise.
  1030.      */
  1031.     protected function checkBrowserOpera()
  1032.     {
  1033.         if ($this->checkBrowserUAWithVersion('Opera Mobi'$this->_agentself::BROWSER_OPERA_MOBILEtrue)) {
  1034.             return true;
  1035.         }
  1036.  
  1037.         if ($this->checkSimpleBrowserUA('Opera Mini'$this->_agentself::BROWSER_OPERA_MINItrue)) {
  1038.             return true;
  1039.         }
  1040.  
  1041.         $version '';
  1042.         $found $this->checkBrowserUAWithVersion('Opera'$this->_agentself::BROWSER_OPERA);
  1043.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  1044.             $version $this->getVersion();
  1045.         }
  1046.  
  1047.         if (!$found || $version == ''{
  1048.             if ($this->checkSimpleBrowserUA('Opera'$this->_agentself::BROWSER_OPERA)) {
  1049.                 return true;
  1050.             }
  1051.         }
  1052.  
  1053.         if (!$found && $this->checkSimpleBrowserUA('Chrome'$this->_agentself::BROWSER_CHROME) ) {
  1054.             if ($this->checkSimpleBrowserUA('OPR/'$this->_agentself::BROWSER_OPERA)) {
  1055.                 return true;
  1056.             }
  1057.         }
  1058.  
  1059.         return $found;
  1060.     }
  1061.  
  1062.     /**
  1063.      * Determine if the browser is Phoenix or not. Phoenix was the name of Firefox from version 0.1 to 0.5.
  1064.      * @access protected
  1065.      * @return boolean Returns true if the browser is Phoenix, false otherwise.
  1066.      */
  1067.     protected function checkBrowserPhoenix()
  1068.     {
  1069.         return $this->checkSimpleBrowserUA('Phoenix'$this->_agentself::BROWSER_PHOENIX);
  1070.     }
  1071.  
  1072.     /**
  1073.      * Determine what is the browser used by the user.
  1074.      * @access protected
  1075.      * @return boolean Returns true if the browser has been identified, false otherwise.
  1076.      */
  1077.     protected function checkBrowsers()
  1078.     {
  1079.         //Changing the check order can break the class detection results!
  1080.         return
  1081.                /* Major browsers and browsers that need to be detected in a special order */
  1082.                $this->checkBrowserMsnTv(||            /* MSN TV is based on IE so we must check for MSN TV before IE */
  1083.                $this->checkBrowserInternetExplorer(||
  1084.                $this->checkBrowserOpera(||            /* Opera must be checked before Firefox, Netscape and Chrome to avoid conflicts */
  1085.                $this->checkBrowserEdge(||             /* Edge must be checked before Firefox, Safari and Chrome to avoid conflicts */
  1086.                $this->checkBrowserVivaldi(||          /* Vivaldi must be checked before Chrome and Safari to avoid conflicts */
  1087.                $this->checkBrowserSamsung(||          /* Samsung Internet browser must be checked before Chrome and Safari to avoid conflicts */
  1088.                $this->checkBrowserChrome(||           /* Chrome must be checked before Netscaoe and Mozilla to avoid conflicts */
  1089.                $this->checkBrowserOmniWeb(||          /* OmniWeb must be checked before Safari (on which it's based on) and Netscape (since it have Mozilla UAs) */
  1090.                $this->checkBrowserIcab(||             /* Check iCab before Netscape since iCab have Mozilla UAs */
  1091.                $this->checkBrowserNetPositive(||      /* Check NetPositive before Netscape since NetPositive have Mozilla UAs */
  1092.                $this->checkBrowserNetscape(||         /* Must be checked before Firefox since Netscape 8-9 are based on Firefox */
  1093.                $this->checkBrowserIceCat(||           /* Check IceCat and IceWeasel before Firefox since they are GNU builds of Firefox */
  1094.                $this->checkBrowserIceWeasel(||
  1095.                $this->checkBrowserGaleon(||           /* Galeon is based on Firefox and needs to be tested before Firefox is tested */
  1096.                $this->checkBrowserFirefox(||
  1097.                /* Current browsers that don't need to be detected in any special order */
  1098.                $this->checkBrowserKonqueror(||
  1099.                $this->checkBrowserLynx(||
  1100.                $this->checkBrowserAmaya(||
  1101.                /* Mobile */
  1102.                $this->checkBrowserAndroid(||
  1103.                $this->checkBrowserBlackBerry(||
  1104.                $this->checkBrowserNokia(||
  1105.                /* Bots */
  1106.                $this->checkBrowserGooglebot(||
  1107.                $this->checkBrowserBingbot(||
  1108.                $this->checkBrowserMsnBot(||
  1109.                $this->checkBrowserSlurp(||
  1110.                $this->checkBrowserYahooMultimedia(||
  1111.                $this->checkBrowserW3CValidator(||
  1112.                /* WebKit base check (after most other checks) */
  1113.                $this->checkBrowserSafari(||
  1114.                /* Deprecated browsers that don't need to be detected in any special order */
  1115.                $this->checkBrowserFirebird(||
  1116.                $this->checkBrowserPhoenix(||
  1117.                /* Mozilla is such an open standard that it must be checked last */
  1118.                $this->checkBrowserMozilla();
  1119.     }
  1120.  
  1121.     /**
  1122.      * Determine if the browser is Safari or not.
  1123.      * @access protected
  1124.      * @link http://www.apple.com/safari/
  1125.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1126.      * @link http://en.wikipedia.org/wiki/Safari_version_history#Release_history
  1127.      * @return boolean Returns true if the browser is Safari, false otherwise.
  1128.      */
  1129.     protected function checkBrowserSafari()
  1130.     {
  1131.         $version '';
  1132.  
  1133.         //Check for current versions of Safari
  1134.         $found $this->checkBrowserUAWithVersion(array('Safari''AppleWebKit')$this->_agentself::BROWSER_SAFARI);
  1135.         if ($found && $this->getVersion(!= self::VERSION_UNKNOWN{
  1136.             $version $this->getVersion();
  1137.         }
  1138.  
  1139.         //Safari 1-2 didn't had a "Version" string in the UA, only a WebKit build and/or Safari build, extract version from these...
  1140.         if (!$found || $version == ''{
  1141.             if (preg_match('/.*Safari[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  1142.                 $version $this->safariBuildToSafariVer($matches[1]);
  1143.                 $found true;
  1144.             }
  1145.         }
  1146.         if (!$found || $version == ''{
  1147.             if (preg_match('/.*AppleWebKit[ (\/]*([a-z0-9.-]*)/i'$this->_agent$matches)) {
  1148.                 $version $this->webKitBuildToSafariVer($matches[1]);
  1149.                 $found true;
  1150.             }
  1151.         }
  1152.  
  1153.         if ($found{
  1154.             $this->setBrowser(self::BROWSER_SAFARI);
  1155.             $this->setVersion($version);
  1156.             $this->setMobile(false);
  1157.             $this->setRobot(false);
  1158.         }
  1159.  
  1160.         return $found;
  1161.     }
  1162.  
  1163.     /**
  1164.      * Determine if the browser is the Samsung Internet browser or not.
  1165.      * @access protected
  1166.      * @return boolean Returns true if the browser is the the Samsung Internet browser, false otherwise.
  1167.      */
  1168.     protected function checkBrowserSamsung()
  1169.     {
  1170.         return $this->checkSimpleBrowserUA('SamsungBrowser'$this->_agentself::BROWSER_SAMSUNGtrue);
  1171.     }
  1172.  
  1173.     /**
  1174.      * Determine if the browser is the Yahoo! Slurp crawler or not.
  1175.      * @access protected
  1176.      * @return boolean Returns true if the browser is Yahoo! Slurp, false otherwise.
  1177.      */
  1178.     protected function checkBrowserSlurp()
  1179.     {
  1180.         return $this->checkSimpleBrowserUA('Yahoo! Slurp'$this->_agentself::BROWSER_SLURPfalsetrue);
  1181.     }
  1182.  
  1183.     /**
  1184.      * Test the user agent for a specific browser that use a "Version" string (like Safari and Opera). The user agent
  1185.      * should look like: "Version/1.0 Browser name/123.456" or "Browser name/123.456 Version/1.0".
  1186.      * @access protected
  1187.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  1188.      *  agent.
  1189.      * @param string $userAgent The user agent string to work with.
  1190.      * @param string $browserName The literal browser name. Always use a class constant!
  1191.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  1192.      * @param boolean $isRobot Determines if the browser is a robot or not.
  1193.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  1194.      */
  1195.     protected function checkBrowserUAWithVersion($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false)
  1196.     {
  1197.         if (!is_array($uaNameToLookFor)) {
  1198.             $uaNameToLookFor array($uaNameToLookFor);
  1199.         }
  1200.  
  1201.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  1202.             if (stripos($userAgent$currUANameToLookFor!== false{
  1203.                 $version '';
  1204.                 $verParts explode('/'stristr($this->_agent'Version'));
  1205.                 if (count($verParts1{
  1206.                     $verParts explode(' '$verParts[1]);
  1207.                     $version $verParts[0];
  1208.                 }
  1209.  
  1210.                 $this->setBrowser($browserName);
  1211.                 $this->setVersion($version);
  1212.  
  1213.                 $this->setMobile($isMobile);
  1214.                 $this->setRobot($isRobot);
  1215.  
  1216.                 return true;
  1217.             }
  1218.         }
  1219.  
  1220.         return false;
  1221.     }
  1222.  
  1223.     /**
  1224.      * Determine if the browser is Vivaldi or not.
  1225.      * @access protected
  1226.      * @return boolean Returns true if the browser is Vivaldi, false otherwise.
  1227.      */
  1228.     protected function checkBrowserVivaldi()
  1229.     {
  1230.         return $this->checkSimpleBrowserUA('Vivaldi'$this->_agentself::BROWSER_VIVALDI);
  1231.     }
  1232.  
  1233.     /**
  1234.      * Determine if the browser is the W3C Validator or not.
  1235.      * @access protected
  1236.      * @link http://validator.w3.org/
  1237.      * @return boolean Returns true if the browser is the W3C Validator, false otherwise.
  1238.      */
  1239.     protected function checkBrowserW3CValidator()
  1240.     {
  1241.         //Since the W3C validates pages with different robots we will prefix our versions with the part validated on the page...
  1242.  
  1243.         //W3C Link Checker (prefixed with "Link-")
  1244.         if ($this->checkSimpleBrowserUA('W3C-checklink'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1245.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1246.                 $this->setVersion('Link-' $this->getVersion());
  1247.             }
  1248.             return true;
  1249.         }
  1250.  
  1251.         //W3C CSS Validation Service (prefixed with "CSS-")
  1252.         if ($this->checkSimpleBrowserUA('Jigsaw'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1253.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1254.                 $this->setVersion('CSS-' $this->getVersion());
  1255.             }
  1256.             return true;
  1257.         }
  1258.  
  1259.         //W3C mobileOK Checker (prefixed with "mobileOK-")
  1260.         if ($this->checkSimpleBrowserUA('W3C-mobileOK'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue)) {
  1261.             if ($this->getVersion(!= self::VERSION_UNKNOWN{
  1262.                 $this->setVersion('mobileOK-' $this->getVersion());
  1263.             }
  1264.             return true;
  1265.         }
  1266.  
  1267.         //W3C Markup Validation Service (no prefix)
  1268.         return $this->checkSimpleBrowserUA('W3C_Validator'$this->_agentself::BROWSER_W3CVALIDATORfalsetrue);
  1269.     }
  1270.  
  1271.     /**
  1272.      * Determine if the browser is the Yahoo! multimedia crawler or not.
  1273.      * @access protected
  1274.      * @return boolean Returns true if the browser is the Yahoo! multimedia crawler, false otherwise.
  1275.      */
  1276.     protected function checkBrowserYahooMultimedia()
  1277.     {
  1278.         return $this->checkSimpleBrowserUA('Yahoo-MMCrawler'$this->_agentself::BROWSER_YAHOO_MMfalsetrue);
  1279.     }
  1280.  
  1281.     /**
  1282.      * Determine if the user is using an AOL "optimized" browser or not.
  1283.      * @access protected
  1284.      * @return boolean Returns true if the browser is AOL optimized, false otherwise.
  1285.      */
  1286.     protected function checkForAol()
  1287.     {
  1288.         //AOL UAs don't use the "AOL/1.0" format, they uses "AOL 1.0; AOLBuild 100.00;"
  1289.         if (stripos($this->_agent'AOL '!== false{
  1290.             $version '';
  1291.             $verParts explode('AOL 'stristr($this->_agent'AOL '));
  1292.             if (count($verParts1{
  1293.                 $verParts explode(' '$verParts[1]);
  1294.                 $version $verParts[0];
  1295.             }
  1296.  
  1297.             $this->setAol(true);
  1298.             $this->setAolVersion($version);
  1299.  
  1300.             return true;
  1301.         else {
  1302.             $this->setAol(false);
  1303.             $this->setAolVersion('');
  1304.  
  1305.             return false;
  1306.         }
  1307.     }
  1308.  
  1309.     /**
  1310.      * Determine the user's platform.
  1311.      * @access protected
  1312.      */
  1313.     protected function checkPlatform()
  1314.     {
  1315.         /* Mobile platforms */
  1316.         if (stripos($this->_agent'Windows Phone'!== false ||     /* Check Windows Phone (formerly Windows Mobile) before Windows */
  1317.                 stripos($this->_agent'IEMobile'!== false{
  1318.             $this->setPlatform(self::PLATFORM_WINDOWS_PHONE);
  1319.             $this->setMobile(true);
  1320.         else if (stripos($this->_agent'Windows CE'!== false/* Check Windows CE before Windows */
  1321.             $this->setPlatform(self::PLATFORM_WINDOWS_CE);
  1322.             $this->setMobile(true);
  1323.         else if (stripos($this->_agent'iPhone'!== false{     /* Check iPad/iPod/iPhone before Macintosh */
  1324.             $this->setPlatform(self::PLATFORM_IPHONE);
  1325.             $this->setMobile(true);
  1326.         else if (stripos($this->_agent'iPad'!== false{
  1327.             $this->setPlatform(self::PLATFORM_IPAD);
  1328.             $this->setMobile(true);
  1329.         else if (stripos($this->_agent'iPod'!== false{
  1330.             $this->setPlatform(self::PLATFORM_IPOD);
  1331.             $this->setMobile(true);
  1332.         else if (stripos($this->_agent'Android'!== false{
  1333.             $this->setPlatform(self::PLATFORM_ANDROID);
  1334.             $this->setMobile(true);
  1335.         else if (stripos($this->_agent'Symbian'!== false{
  1336.             $this->setPlatform(self::PLATFORM_SYMBIAN);
  1337.             $this->setMobile(true);
  1338.         else if (stripos($this->_agent'BlackBerry'!== false ||
  1339.                 stripos($this->_agent'BB10'!== false ||
  1340.                 stripos($this->_agent'RIM Tablet OS'!== false{
  1341.             $this->setPlatform(self::PLATFORM_BLACKBERRY);
  1342.             $this->setMobile(true);
  1343.         else if (stripos($this->_agent'Nokia'!== false{
  1344.             $this->setPlatform(self::PLATFORM_NOKIA);
  1345.             $this->setMobile(true);
  1346.  
  1347.         /* Desktop platforms */
  1348.         else if (stripos($this->_agent'Windows'!== false{
  1349.             $this->setPlatform(self::PLATFORM_WINDOWS);
  1350.         else if (stripos($this->_agent'Macintosh'!== false{
  1351.             $this->setPlatform(self::PLATFORM_MACINTOSH);
  1352.         else if (stripos($this->_agent'Linux'!== false{
  1353.             $this->setPlatform(self::PLATFORM_LINUX);
  1354.         else if (stripos($this->_agent'FreeBSD'!== false{
  1355.             $this->setPlatform(self::PLATFORM_FREEBSD);
  1356.         else if (stripos($this->_agent'OpenBSD'!== false{
  1357.             $this->setPlatform(self::PLATFORM_OPENBSD);
  1358.         else if (stripos($this->_agent'NetBSD'!== false{
  1359.             $this->setPlatform(self::PLATFORM_NETBSD);
  1360.  
  1361.         /* Discontinued */
  1362.         else if (stripos($this->_agent'OpenSolaris'!== false{
  1363.             $this->setPlatform(self::PLATFORM_OPENSOLARIS);
  1364.         else if (stripos($this->_agent'OS/2'!== false{
  1365.             $this->setPlatform(self::PLATFORM_OS2);
  1366.         else if (stripos($this->_agent'BeOS'!== false{
  1367.             $this->setPlatform(self::PLATFORM_BEOS);
  1368.         else if (stripos($this->_agent'SunOS'!== false{
  1369.             $this->setPlatform(self::PLATFORM_SUNOS);
  1370.  
  1371.         /* Generic */
  1372.         else if (stripos($this->_agent'Win'!== false{
  1373.             $this->setPlatform(self::PLATFORM_WINDOWS);
  1374.         else if (stripos($this->_agent'Mac'!== false{
  1375.             $this->setPlatform(self::PLATFORM_MACINTOSH);
  1376.         }
  1377.  
  1378.         //Check if it's a 64-bit platform
  1379.         if (stripos($this->_agent'WOW64'!== false || stripos($this->_agent'Win64'!== false{
  1380.             $this->set64bit(true);
  1381.         }
  1382.  
  1383.         $this->checkPlatformVersion();
  1384.     }
  1385.  
  1386.     /**
  1387.      * Determine the user's platform version.
  1388.      * @access protected
  1389.      */
  1390.     protected function checkPlatformVersion()
  1391.     {
  1392.         $result '';
  1393.  
  1394.         switch ($this->getPlatform()) {
  1395.             case self::PLATFORM_WINDOWS:
  1396.                 if (preg_match('/Windows NT\s*([^\s;\)$]+)/i'$this->_agent$foundVersion)) {
  1397.                     //Windows NT family
  1398.                     $result 'NT ' $foundVersion[1];
  1399.                 else {
  1400.                     //Windows 3.x / 9x family
  1401.                     //https://support.microsoft.com/en-us/kb/158238
  1402.                     if (stripos($this->_agent'Win 9x 4.90'!== false || stripos($this->_agent'Windows ME'!== false{
  1403.                         $result '4.90.3000'//Windows Me version range from 4.90.3000 to 4.90.3000A
  1404.                     else if (stripos($this->_agent'Windows 98'!== false{
  1405.                         $result '4.10'//Windows 98 version range from 4.10.1998 to 4.10.2222B
  1406.                     else if (stripos($this->_agent'Windows 95'!== false{
  1407.                         $result '4.00'//Windows 95 version range from 4.00.950 to 4.03.1214
  1408.                     else if (preg_match('/Windows 3\.([^\s;\)$]+)/i'$this->_agent$foundVersion)) {
  1409.                         $result '3.' $foundVersion[1];
  1410.                     else if (stripos($this->_agent'Win16'!== false{
  1411.                         $result '3.1';
  1412.                     }
  1413.                 }
  1414.             break;
  1415.  
  1416.             case self::PLATFORM_MACINTOSH:
  1417.                 if (preg_match('/Mac OS X\s*([^\s;\)$]+)/i'$this->_agent$foundVersion)) {
  1418.                     $result str_replace('_''.'$foundVersion[1]);
  1419.                 else if (stripos($this->_agent'Mac OS X'!== false{
  1420.                     $result '10';
  1421.                 }
  1422.             break;
  1423.  
  1424.             case self::PLATFORM_ANDROID:
  1425.                 if (preg_match('/Android\s+([^\s;$]+)/i'$this->_agent$foundVersion)) {
  1426.                     $result $foundVersion[1];
  1427.                 }
  1428.             break;
  1429.         }
  1430.  
  1431.         if (trim($result== ''{
  1432.             $result self::PLATFORM_VERSION_UNKNOWN;
  1433.         }
  1434.         $this->setPlatformVersion($result);
  1435.     }
  1436.  
  1437.     /**
  1438.      * Test the user agent for a specific browser where the browser name is immediately followed by the version number.
  1439.      * The user agent should look like: "Browser name/1.0" or "Browser 1.0;".
  1440.      * @access protected
  1441.      * @param mixed $uaNameToLookFor The string (or array of strings) representing the browser name to find in the user
  1442.      *  agent.
  1443.      * @param string $userAgent The user agent string to work with.
  1444.      * @param string $browserName The literal browser name. Always use a class constant!
  1445.      * @param boolean $isMobile Determines if the browser is from a mobile device.
  1446.      * @param boolean $isRobot Determines if the browser is a robot or not.
  1447.      * @param string $separator The separator string used to split the browser name and the version number in the user
  1448.      *  agent.
  1449.      * @return boolean Returns true if we found the browser we were looking for, false otherwise.
  1450.      */
  1451.     protected function checkSimpleBrowserUA($uaNameToLookFor$userAgent$browserName$isMobile false$isRobot false$separator '/')
  1452.     {
  1453.         if (!is_array($uaNameToLookFor)) {
  1454.             $uaNameToLookFor array($uaNameToLookFor);
  1455.         }
  1456.  
  1457.         foreach ($uaNameToLookFor as $currUANameToLookFor{
  1458.             if (stripos($userAgent$currUANameToLookFor!== false{
  1459.                 //Many browsers don't use the standard "Browser/1.0" format, they uses "Browser 1.0;" instead
  1460.                 if (stripos($userAgent$currUANameToLookFor $separator=== false{
  1461.                     $userAgent str_ireplace($currUANameToLookFor ' '$currUANameToLookFor $separator$this->_agent);
  1462.                 }
  1463.  
  1464.                 $version '';
  1465.                 $verParts explode($separatorstristr($userAgent$currUANameToLookFor));
  1466.                 if (count($verParts1{
  1467.                     $verParts explode(' '$verParts[1]);
  1468.                     $version $verParts[0];
  1469.                 }
  1470.  
  1471.                 $this->setBrowser($browserName);
  1472.                 $this->setVersion($version);
  1473.  
  1474.                 $this->setMobile($isMobile);
  1475.                 $this->setRobot($isRobot);
  1476.  
  1477.                 return true;
  1478.             }
  1479.         }
  1480.  
  1481.         return false;
  1482.     }
  1483.  
  1484.     /**
  1485.      * Detect the user environment from the details in the user agent string.
  1486.      * @access protected
  1487.      */
  1488.     protected function detect()
  1489.     {
  1490.         $this->checkBrowsers();
  1491.         $this->checkPlatform()//Check the platform after the browser since some platforms can change the mobile value
  1492.         $this->checkForAol();
  1493.     }
  1494.  
  1495.     /**
  1496.      * Clean a version string from unwanted characters.
  1497.      * @access protected
  1498.      * @param string $version The version string to clean.
  1499.      * @return string Returns the cleaned version number string.
  1500.      */
  1501.     protected function cleanVersion($version)
  1502.     {
  1503.         //Clear anything that is in parentheses (and the parentheses themselves) - will clear started but unclosed ones too
  1504.         $cleanVer preg_replace('/\([^)]+\)?/'''$version);
  1505.         //Replace with a space any character which is NOT an alphanumeric, dot (.), hyphen (-), underscore (_) or space
  1506.         $cleanVer preg_replace('/[^0-9.a-zA-Z_ -]/'' '$cleanVer);
  1507.         //Remove trailing and leading spaces
  1508.         $cleanVer trim($cleanVer);
  1509.         //Remove double spaces if any
  1510.         while (strpos($cleanVer'  '!== false{
  1511.             $cleanVer str_replace('  '' '$cleanVer);
  1512.         }
  1513.  
  1514.         return $cleanVer;
  1515.     }
  1516.  
  1517.     /**
  1518.      * Convert the macOS version numbers to the operating system name. For instance '10.7' returns 'Mac OS X Lion'.
  1519.      * @access protected
  1520.      * @param string $macVer The macOS version numbers as a string.
  1521.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  1522.      *  numbers.
  1523.      */
  1524.     protected function macVerToStr($macVer)
  1525.     {
  1526.         //https://en.wikipedia.org/wiki/OS_X#Release_history
  1527.  
  1528.         if ($this->_platformVersion === '10'{
  1529.             return 'Mac OS X'//Unspecified Mac OS X version
  1530.         else if ($this->compareVersions($macVer'10.12'>= && $this->compareVersions($macVer'10.13'0{
  1531.             return 'macOS Sierra';
  1532.         else if ($this->compareVersions($macVer'10.11'>= && $this->compareVersions($macVer'10.12'0{
  1533.             return 'OS X El Capitan';
  1534.         else if ($this->compareVersions($macVer'10.10'>= && $this->compareVersions($macVer'10.11'0{
  1535.             return 'OS X Yosemite';
  1536.         else if ($this->compareVersions($macVer'10.9'>= && $this->compareVersions($macVer'10.10'0{
  1537.             return 'OS X Mavericks';
  1538.         else if ($this->compareVersions($macVer'10.8'>= && $this->compareVersions($macVer'10.9'0{
  1539.             return 'OS X Mountain Lion';
  1540.         else if ($this->compareVersions($macVer'10.7'>= && $this->compareVersions($macVer'10.8'0{
  1541.             return 'Mac OS X Lion';
  1542.         else if ($this->compareVersions($macVer'10.6'>= && $this->compareVersions($macVer'10.7'0{
  1543.             return 'Mac OS X Snow Leopard';
  1544.         else if ($this->compareVersions($macVer'10.5'>= && $this->compareVersions($macVer'10.6'0{
  1545.             return 'Mac OS X Leopard';
  1546.         else if ($this->compareVersions($macVer'10.4'>= && $this->compareVersions($macVer'10.5'0{
  1547.             return 'Mac OS X Tiger';
  1548.         else if ($this->compareVersions($macVer'10.3'>= && $this->compareVersions($macVer'10.4'0{
  1549.             return 'Mac OS X Panther';
  1550.         else if ($this->compareVersions($macVer'10.2'>= && $this->compareVersions($macVer'10.3'0{
  1551.             return 'Mac OS X Jaguar';
  1552.         else if ($this->compareVersions($macVer'10.1'>= && $this->compareVersions($macVer'10.2'0{
  1553.             return 'Mac OS X Puma';
  1554.         else if ($this->compareVersions($macVer'10.0'>= && $this->compareVersions($macVer'10.1'0{
  1555.             return 'Mac OS X Cheetah';
  1556.         else {
  1557.             return self::PLATFORM_VERSION_UNKNOWN//Unknown/unnamed Mac OS version
  1558.         }
  1559.     }
  1560.  
  1561.     /**
  1562.      * Get the integer value of a string variable.
  1563.      * @access protected
  1564.      * @param string $intStr The scalar value being converted to an integer.
  1565.      * @return int The integer value of $intStr on success, or 0 on failure.
  1566.      */
  1567.     protected function parseInt($intStr)
  1568.     {
  1569.         return intval($intStr10);
  1570.     }
  1571.  
  1572.     /**
  1573.      * Reset all the properties of the class.
  1574.      * @access protected
  1575.      */
  1576.     protected function reset()
  1577.     {
  1578.         $this->_agent = '';
  1579.         $this->_aolVersion = '';
  1580.         $this->_browserName = self::BROWSER_UNKNOWN;
  1581.         $this->_compatibilityViewName = '';
  1582.         $this->_compatibilityViewVer = '';
  1583.         $this->_is64bit = false;
  1584.         $this->_isAol = false;
  1585.         $this->_isMobile = false;
  1586.         $this->_isRobot = false;
  1587.         $this->_platform = self::PLATFORM_UNKNOWN;
  1588.         $this->_platformVersion = self::PLATFORM_VERSION_UNKNOWN;
  1589.         $this->_version = self::VERSION_UNKNOWN;
  1590.     }
  1591.  
  1592.     /**
  1593.      * Convert a Safari build number to a Safari version number.
  1594.      * @access protected
  1595.      * @param string $version A string representing the version number.
  1596.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1597.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1598.      *  returned.
  1599.      */
  1600.     protected function safariBuildToSafariVer($version)
  1601.     {
  1602.         $verParts explode('.'$version);
  1603.  
  1604.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1605.         while (count($verParts3{
  1606.             $verParts[0;
  1607.         }
  1608.         foreach ($verParts as $i => $currPart{
  1609.             $verParts[$i$this->parseInt($currPart);
  1610.         }
  1611.  
  1612.         switch ($verParts[0]{
  1613.             case 419$result '2.0.4';
  1614.                 break;
  1615.             case 417$result '2.0.3';
  1616.                 break;
  1617.             case 416$result '2.0.2';
  1618.                 break;
  1619.  
  1620.             case 412:
  1621.                 if ($verParts[1>= 5{
  1622.                     $result '2.0.1';
  1623.                 else {
  1624.                     $result '2.0';
  1625.                 }
  1626.                 break;
  1627.  
  1628.             case 312:
  1629.                 if ($verParts[1>= 5{
  1630.                     $result '1.3.2';
  1631.                 else {
  1632.                     if ($verParts[1>= 3{
  1633.                         $result '1.3.1';
  1634.                     else {
  1635.                         $result '1.3';
  1636.                     }
  1637.                 }
  1638.                 break;
  1639.  
  1640.             case 125:
  1641.                 if ($verParts[1>= 11{
  1642.                     $result '1.2.4';
  1643.                 else {
  1644.                     if ($verParts[1>= 9{
  1645.                         $result '1.2.3';
  1646.                     else {
  1647.                         if ($verParts[1>= 7{
  1648.                             $result '1.2.2';
  1649.                         else {
  1650.                             $result '1.2';
  1651.                         }
  1652.                     }
  1653.                 }
  1654.                 break;
  1655.  
  1656.             case 100:
  1657.                 if ($verParts[1>= 1{
  1658.                     $result '1.1.1';
  1659.                 else {
  1660.                     $result '1.1';
  1661.                 }
  1662.                 break;
  1663.  
  1664.             case 85:
  1665.                 if ($verParts[1>= 8{
  1666.                     $result '1.0.3';
  1667.                 else {
  1668.                     if ($verParts[1>= 7{
  1669.                         $result '1.0.2';
  1670.                     else {
  1671.                         $result '1.0';
  1672.                     }
  1673.                 }
  1674.                 break;
  1675.  
  1676.             case 73$result '0.9';
  1677.                 break;
  1678.             case 51$result '0.8.1';
  1679.                 break;
  1680.             case 48$result '0.8';
  1681.                 break;
  1682.  
  1683.             default$result '';
  1684.         }
  1685.  
  1686.         return $result;
  1687.     }
  1688.  
  1689.     /**
  1690.      * Set if the browser is executed from a 64-bit platform.
  1691.      * @access protected
  1692.      * @param boolean $is64bit Value that tells if the browser is executed from a 64-bit platform.
  1693.      */
  1694.     protected function set64bit($is64bit)
  1695.     {
  1696.         $this->_is64bit = $is64bit == true;
  1697.     }
  1698.  
  1699.     /**
  1700.      * Set the browser to be from AOL or not.
  1701.      * @access protected
  1702.      * @param boolean $isAol Value that tells if the browser is AOL or not.
  1703.      */
  1704.     protected function setAol($isAol)
  1705.     {
  1706.         $this->_isAol = $isAol == true;
  1707.     }
  1708.  
  1709.     /**
  1710.      * Set the version of AOL.
  1711.      * @access protected
  1712.      * @param string $version The version of AOL (will be cleaned).
  1713.      */
  1714.     protected function setAolVersion($version)
  1715.     {
  1716.         $cleanVer $this->cleanVersion($version);
  1717.  
  1718.         $this->_aolVersion = $cleanVer;
  1719.     }
  1720.  
  1721.     /**
  1722.      * Set the name of the browser.
  1723.      * @access protected
  1724.      * @param string $browserName The name of the browser.
  1725.      */
  1726.     protected function setBrowser($browserName)
  1727.     {
  1728.         $this->_browserName = $browserName;
  1729.     }
  1730.  
  1731.     /**
  1732.      * Set the browser to be from a mobile device or not.
  1733.      * @access protected
  1734.      * @param boolean $isMobile Value that tells if the browser is on a mobile device or not.
  1735.      */
  1736.     protected function setMobile($isMobile true)
  1737.     {
  1738.         $this->_isMobile = $isMobile == true;
  1739.     }
  1740.  
  1741.     /**
  1742.      * Set the platform on which the browser is on.
  1743.      * @access protected
  1744.      * @param string $platform The name of the platform.
  1745.      */
  1746.     protected function setPlatform($platform)
  1747.     {
  1748.         $this->_platform = $platform;
  1749.     }
  1750.  
  1751.     /**
  1752.      * Set the platform version on which the browser is on.
  1753.      * @access protected
  1754.      * @param string $platformVer The version numbers of the platform.
  1755.      */
  1756.     protected function setPlatformVersion($platformVer)
  1757.     {
  1758.         $this->_platformVersion = $platformVer;
  1759.     }
  1760.  
  1761.     /**
  1762.      * Set the browser to be a robot (crawler) or not.
  1763.      * @access protected
  1764.      * @param boolean $isRobot Value that tells if the browser is a robot or not.
  1765.      */
  1766.     protected function setRobot($isRobot true)
  1767.     {
  1768.         $this->_isRobot = $isRobot == true;
  1769.     }
  1770.  
  1771.     /**
  1772.      * Set the version of the browser.
  1773.      * @access protected
  1774.      * @param string $version The version of the browser.
  1775.      */
  1776.     protected function setVersion($version)
  1777.     {
  1778.         $cleanVer $this->cleanVersion($version);
  1779.  
  1780.         if ($cleanVer == ''{
  1781.             $this->_version = self::VERSION_UNKNOWN;
  1782.         else {
  1783.             $this->_version = $cleanVer;
  1784.         }
  1785.     }
  1786.  
  1787.     /**
  1788.      * Convert a WebKit build number to a Safari version number.
  1789.      * @access protected
  1790.      * @param string $version A string representing the version number.
  1791.      * @link http://web.archive.org/web/20080514173941/http://developer.apple.com/internet/safari/uamatrix.html
  1792.      * @return string Returns the Safari version string. If the version can't be determined, an empty string is
  1793.      *  returned.
  1794.      */
  1795.     protected function webKitBuildToSafariVer($version)
  1796.     {
  1797.         $verParts explode('.'$version);
  1798.  
  1799.         //We need a 3 parts version (version 2 will becomes 2.0.0)
  1800.         while (count($verParts3{
  1801.             $verParts[0;
  1802.         }
  1803.         foreach ($verParts as $i => $currPart{
  1804.             $verParts[$i$this->parseInt($currPart);
  1805.         }
  1806.  
  1807.         switch ($verParts[0]{
  1808.             case 419$result '2.0.4';
  1809.                 break;
  1810.  
  1811.             case 418:
  1812.                 if ($verParts[1>= 8{
  1813.                     $result '2.0.4';
  1814.                 else {
  1815.                     $result '2.0.3';
  1816.                 }
  1817.                 break;
  1818.  
  1819.             case 417$result '2.0.3';
  1820.                 break;
  1821.  
  1822.             case 416$result '2.0.2';
  1823.                 break;
  1824.  
  1825.             case 412:
  1826.                 if ($verParts[1>= 7{
  1827.                     $result '2.0.1';
  1828.                 else {
  1829.                     $result '2.0';
  1830.                 }
  1831.                 break;
  1832.  
  1833.             case 312:
  1834.                 if ($verParts[1>= 8{
  1835.                     $result '1.3.2';
  1836.                 else {
  1837.                     if ($verParts[1>= 5{
  1838.                         $result '1.3.1';
  1839.                     else {
  1840.                         $result '1.3';
  1841.                     }
  1842.                 }
  1843.                 break;
  1844.  
  1845.             case 125:
  1846.                 if ($this->compareVersions('5.4'$verParts[1'.' $verParts[2]== -1{
  1847.                     $result '1.2.4'//125.5.5+
  1848.                 else {
  1849.                     if ($verParts[1>= 4{
  1850.                         $result '1.2.3';
  1851.                     else {
  1852.                         if ($verParts[1>= 2{
  1853.                             $result '1.2.2';
  1854.                         else {
  1855.                             $result '1.2';
  1856.                         }
  1857.                     }
  1858.                 }
  1859.                 break;
  1860.  
  1861.             //WebKit 100 can be either Safari 1.1 (Safari build 100) or 1.1.1 (Safari build 100.1)
  1862.             //for this reason, check the Safari build before the WebKit build.
  1863.             case 100$result '1.1.1';
  1864.                 break;
  1865.  
  1866.             case 85:
  1867.                 if ($verParts[1>= 8{
  1868.                     $result '1.0.3';
  1869.                 else {
  1870.                     if ($verParts[1>= 7{
  1871.                         //WebKit 85.7 can be either Safari 1.0 (Safari build 85.5) or 1.0.2 (Safari build 85.7)
  1872.                         //for this reason, check the Safari build before the WebKit build.
  1873.                         $result '1.0.2';
  1874.                     else {
  1875.                         $result '1.0';
  1876.                     }
  1877.                 }
  1878.                 break;
  1879.  
  1880.             case 73$result '0.9';
  1881.                 break;
  1882.             case 51$result '0.8.1';
  1883.                 break;
  1884.             case 48$result '0.8';
  1885.                 break;
  1886.  
  1887.             default$result '';
  1888.         }
  1889.  
  1890.         return $result;
  1891.     }
  1892.  
  1893.     /**
  1894.      * Convert the Windows NT family version numbers to the operating system name. For instance '5.1' returns
  1895.      * 'Windows XP'.
  1896.      * @access protected
  1897.      * @param string $winVer The Windows NT family version numbers as a string.
  1898.      * @param boolean $returnServerFlavor Since some Windows NT versions have the same values, this flag determines if
  1899.      *  the Server flavor is returned or not. For instance Windows 8.1 and Windows Server 2012 R2 both use version 6.3.
  1900.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  1901.      *  numbers.
  1902.      */
  1903.     protected function windowsNTVerToStr($winVer$returnServerFlavor false)
  1904.     {
  1905.         //https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
  1906.  
  1907.         $cleanWinVer explode('.'$winVer);
  1908.         while (count($cleanWinVer2{
  1909.             array_pop($cleanWinVer);
  1910.         }
  1911.         $cleanWinVer implode('.'$cleanWinVer);
  1912.  
  1913.         if ($this->compareVersions($cleanWinVer'11'>= 0{
  1914.             //Future versions of Windows
  1915.             return self::PLATFORM_WINDOWS ' ' $winVer;
  1916.         else if ($this->compareVersions($cleanWinVer'10'>= 0{
  1917.             //Current version of Windows
  1918.             return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2016'(self::PLATFORM_WINDOWS ' 10');
  1919.         else if ($this->compareVersions($cleanWinVer'7'0{
  1920.             if ($this->compareVersions($cleanWinVer'6.3'== 0{
  1921.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2012 R2'(self::PLATFORM_WINDOWS ' 8.1');
  1922.             else if ($this->compareVersions($cleanWinVer'6.2'== 0{
  1923.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2012'(self::PLATFORM_WINDOWS ' 8');
  1924.             else if ($this->compareVersions($cleanWinVer'6.1'== 0{
  1925.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2008 R2'(self::PLATFORM_WINDOWS ' 7');
  1926.             else if ($this->compareVersions($cleanWinVer'6'== 0{
  1927.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2008'(self::PLATFORM_WINDOWS ' Vista');
  1928.             else if ($this->compareVersions($cleanWinVer'5.2'== 0{
  1929.                 return $returnServerFlavor (self::PLATFORM_WINDOWS ' Server 2003 / ' self::PLATFORM_WINDOWS ' Server 2003 R2'(self::PLATFORM_WINDOWS ' XP x64 Edition');
  1930.             else if ($this->compareVersions($cleanWinVer'5.1'== 0{
  1931.                 return self::PLATFORM_WINDOWS ' XP';
  1932.             else if ($this->compareVersions($cleanWinVer'5'== 0{
  1933.                 return self::PLATFORM_WINDOWS ' 2000';
  1934.             else if ($this->compareVersions($cleanWinVer'5'&& $this->compareVersions($cleanWinVer'3'>= 0{
  1935.                 return self::PLATFORM_WINDOWS ' NT ' $winVer;
  1936.             }
  1937.         }
  1938.  
  1939.         return self::PLATFORM_VERSION_UNKNOWN//Invalid Windows NT version
  1940.     }
  1941.  
  1942.     /**
  1943.      * Convert the Windows 3.x & 9x family version numbers to the operating system name. For instance '4.10.1998'
  1944.      * returns 'Windows 98'.
  1945.      * @access protected
  1946.      * @param string $winVer The Windows 3.x or 9x family version numbers as a string.
  1947.      * @return string The operating system name or the constant PLATFORM_VERSION_UNKNOWN if nothing match the version
  1948.      *  numbers.
  1949.      */
  1950.     protected function windowsVerToStr($winVer)
  1951.     {
  1952.         //https://support.microsoft.com/en-us/kb/158238
  1953.  
  1954.         if ($this->compareVersions($winVer'4.90'>= && $this->compareVersions($winVer'4.91'0{
  1955.             return self::PLATFORM_WINDOWS ' Me'//Normally range from 4.90.3000 to 4.90.3000A
  1956.         else if ($this->compareVersions($winVer'4.10'>= && $this->compareVersions($winVer'4.11'0{
  1957.             return self::PLATFORM_WINDOWS ' 98'//Normally range from 4.10.1998 to 4.10.2222B
  1958.         else if ($this->compareVersions($winVer'4'>= && $this->compareVersions($winVer'4.04'0{
  1959.             return self::PLATFORM_WINDOWS ' 95'//Normally range from 4.00.950 to 4.03.1214
  1960.         else if ($this->compareVersions($winVer'3.1'== || $this->compareVersions($winVer'3.11'== 0{
  1961.             return self::PLATFORM_WINDOWS ' ' $winVer;
  1962.         else if ($this->compareVersions($winVer'3.10'== 0{
  1963.             return self::PLATFORM_WINDOWS ' 3.1';
  1964.         else {
  1965.             return self::PLATFORM_VERSION_UNKNOWN//Invalid Windows version
  1966.         }
  1967.     }
  1968. }

Documentation generated on Fri, 19 Aug 2016 14:44:02 -0400 by phpDocumentor 1.4.3