PHP判断浏览器类型

今天做的项目需要根据用户浏览器的类型而做一些不同的处理,于是稍微研究了一下使用php判断浏览器类型的方法,发现解决这个问题其实很简单,只要熟悉 $_SERVER[‘HTTP_USER_AGENT’] 这个常量的用法就行了。下面我们就来通过 $_SERVER[‘HTTP_USER_AGENT’] 来写一个php判断浏览器类型的办法。

01 function my_get_browser(){
02     if(empty($_SERVER['HTTP_USER_AGENT'])){
03         return '命令行,机器人来了!';
04     }
05     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0')){
06         return 'Internet Explorer 9.0';
07     }
08     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0')){
09         return 'Internet Explorer 8.0';
10     }
11     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7.0')){
12         return 'Internet Explorer 7.0';
13     }
14     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 6.0')){
15         return 'Internet Explorer 6.0';
16     }
17     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')){
18         return 'Firefox';
19     }
20     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'Chrome')){
21         return 'Chrome';
22     }
23     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'Safari')){
24         return 'Safari';
25     }
26     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'Opera')){
27         return 'Opera';
28     }
29     if(false!==strpos($_SERVER['HTTP_USER_AGENT'],'360SE')){
30         return '360SE';
31     }
32 }

这里主要用到了 $_SERVER[‘HTTP_USER_AGENT’],这个常量是用来检查浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好。用法很简单,自己在程序里面打印出来看看就明白了。

另外 php 判断浏览器的类型还可以通过 php 系统函数 get_browser() 函数,这个函数将会返回用户浏览器的一些性能数据。该函数通过查阅用户的 browscap.ini 文件,来测定用户浏览器的性能。若成功,则该函数返回包含用户浏览器信息的一个对象或一个数组,若失败,则返回 false。

get_browser 语法

get_browser(user_agent,return_array)

这个函数有两个参数,参数意义解释如下:

user_agent 可选。规定 HTTP 用户代理的名称。默认是 $HTTP_USER_AGENT 的值。您可以通过设置 NULL 绕过该参数。

return_array 可选。如果该参数设置为 true,本函数会返回一个数组而不是对象。

对于 php 通过 $_SERVER[‘HTTP_USER_AGENT’] 和 get_browser 获取的浏览器信息,我们可以通过如下例子来认识一下:

1 <?php
2 echo $_SERVER['HTTP_USER_AGENT'] . "<br /><br />";
3 $browser = get_browser(null,true);
4 print_r($browser);
5 ?>

结果将输出:

Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

Array(
[browser_name_regex] => ^mozilla/.\.0
(compatible; msie 6\.0.*;.*windows nt 5\.1.*\.net clr.*).*$
[browser_name_pattern] => Mozilla/?.0
(compatible; MSIE 6.0*;*Windows NT 5.1*.NET CLR*)*
[parent] => IE 6.0
[platform] => WinXP
[netclr] => 1
[browser] => IE
[version] => 6.0
[majorver] => 6
[minorver] => 0


=> 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] => 1
[vbscript] => 1


=> 1
[javaapplets] => 1
[activexcontrols] => 1
[cdf] => 1
[aol] =>
[beta] =>
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[ak] =>
[sk] =>
)

但是通过PHP的get_browser()函数获取客户端浏览器相关信息是有条件的,如果你直接使用一般会报出如下这个错误:

Warning: get_browser() [function.get-browser]: browscap ini directive not set in ……

通过查询 php 手册,得到的解释是:为了使用这个函数,你必须在php.ini文件里面增加一句指向 browscap.ini 文件的配置,browscap.ini文件里面记录了所有已存在的浏览器的类型及其信息,所以你要下载最新的这个文件,下载browscap.ini后放到服务器某个位置,get_browser()在使用时就是将获取的客户端信息与此文件进行对比,如果能找到,则返回相应类型。

由上看来要想使用 get_browser() 获取浏览器类型代价不小啊!

另外还有一种php判断浏览器类型的办法,即使用一个国外牛人写的开源代码。国外有个叫mavrick的网站,上面有关于浏览器的项目,一直更新所写的Browser类,我最新看到的这个类可以获取包括iPhone、BlackBerry、win、mac、linux、OS、BeOS等平台上的浏览器信息,功能可以说是十分强大。下载这个文件时要根据自己使用的PHP版本去选择。该类的具体代码如下:

0001 <?php
0002 /**
0003  * File: Browser.php
0004  * Author: Chris Schuld (http://chrisschuld.com/)
0006  * Last Modified: August 20th, 2010
0007  * @version 1.9
0008  * @package PegasusPHP
0009  *
0010  * Copyright (C) 2008-2010 Chris Schuld  (chris@chrisschuld.com)
0011  *
0012  * This program is free software; you can redistribute it and/or
0013  * modify it under the terms of the GNU General Public License as
0014  * published by the Free Software Foundation; either version 2 of
0015  * the License, or (at your option) any later version.
0016  *
0017  * This program is distributed in the hope that it will be useful,
0018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0020  * GNU General Public License for more details at:
0022  *
0023  *
0024  * Typical Usage:
0025  *
0026  *   $browser = new Browser();
0027  *   if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
0028  *      echo 'You have FireFox version 2 or greater';
0029  *   }
0030  *
0031  * User Agents Sampled from: http://www.useragentstring.com/
0032  *
0033  * This implementation is based on the original work from Gary White
0035  *
0036  * UPDATES:
0037  *
0038  * 2010-08-20 (v1.9):
0039  *  + Added MSN Explorer Browser (legacy)
0040  *  + Added Bing/MSN Robot (Thanks Rob MacDonald)
0041  *  + Added the Android Platform (PLATFORM_ANDROID)
0042  *  + Fixed issue with Android 1.6/2.2 (Thanks Tom Hirashima)
0043  *
0044  * 2010-04-27 (v1.8):
0045  *  + Added iPad Support
0046  *
0047  * 2010-03-07 (v1.7):
0048  *  + *MAJOR* Rebuild (preg_match and other "slow" routine removal(s))
0049  *  + Almost allof Gary's original code has been replaced
0050  *  + Large PHPUNIT testing environment created to validate new releases and additions
0051  *  + Added FreeBSD Platform
0052  *  + Added OpenBSD Platform
0053  *  + Added NetBSD Platform
0054  *  + Added SunOS Platform
0055  *  + Added OpenSolaris Platform
0056  *  + Added support of the Iceweazel Browser
0057  *  + Added isChromeFrame() call to check if chromeframe is in use
0058  *  + Moved the Opera check in front of the Firefox check due to legacy Opera User Agents
0059  *  + Added the __toString() method (Thanks Deano)
0060  *
0061  * 2009-11-15:
0062  *  + Updated the checkes for Firefox
0063  *  + Added the NOKIA platform
0064  *  + Added Checks for the NOKIA brower(s)
0065  
0066  * 2009-11-08:
0067  *  + PHP 5.3 Support
0068  *  + Added support for BlackBerry OS and BlackBerry browser
0069  *  + Added support for the Opera Mini browser
0070  *  + Added additional documenation
0071  *  + Added support for isRobot() and isMobile()
0072  *  + Added support for Opera version 10
0073  *  + Added support for deprecated Netscape Navigator version 9
0074  *  + Added support for IceCat
0075  *  + Added support for Shiretoko
0076  *
0077  * 2010-04-27 (v1.8):
0078  *  + Added iPad Support
0079  *
0080  * 2009-08-18:
0081  *  + Updated to support PHP 5.3 - removed all deprecated function calls
0082  *  + Updated to remove all double quotes (") -- converted to single quotes (')
0083  *
0084  * 2009-04-27:
0085  *  + Updated the IE check to remove a typo and bug (thanks John)
0086  *
0087  * 2009-04-22:
0088  *  + Added detection for GoogleBot
0089  *  + Added detection for the W3C Validator.
0090  *  + Added detection for Yahoo! Slurp
0091  *
0092  * 2009-03-14:
0093  *  + Added detection for iPods.
0094  *  + Added Platform detection for iPhones
0095  *  + Added Platform detection for iPods
0096  *
0097  * 2009-02-16: (Rick Hale)
0098  *  + Added version detection for Android phones.
0099  *
0100  * 2008-12-09:
0101  *  + Removed unused constant
0102  *
0103  * 2008-11-07:
0104  *  + Added Google's Chrome to the detection list
0105  *  + Added isBrowser(string) to the list of functions special thanks to
0106  *Daniel 'mavrick' Lang for the function concept (http://mavrick.id.au)
0107  *
0108  *
0109  * Gary White noted: "Since browser detection is so unreliable, I am
0110  * no longer maintaining this script. You are free to use and or
0111  * modify/update it as you want, however the author assumes no
0112  * responsibility for the accuracy of the detected values."
0113  *
0114  * Anyone experienced with Gary's script might be interested in these notes:
0115  *
0116  *   Added class constants
0117  *   Added detection and version detection for Google's Chrome
0118  *   Updated the version detection for Amaya
0119  *   Updated the version detection for Firefox
0120  *   Updated the version detection for Lynx
0121  *   Updated the version detection for WebTV
0122  *   Updated the version detection for NetPositive
0123  *   Updated the version detection for IE
0124  *   Updated the version detection for OmniWeb
0125  *   Updated the version detection for iCab
0126  *   Updated the version detection for Safari
0127  *   Updated Safari to remove mobile devices (iPhone)
0128  *   Added detection for iPhone
0129  *   Added detection for robots
0130  *   Added detection for mobile devices
0131  *   Added detection for BlackBerry
0132  *   Removed Netscape checks (matches heavily with firefox & mozilla)
0133  *
0134  */
0135
0136 class Browser {
0137     private $_agent '';
0138     private $_browser_name '';
0139     private $_version '';
0140     private $_platform '';
0141     private $_os '';
0142     private $_is_aol = false;
0143     private $_is_mobile = false;
0144     private $_is_robot = false;
0145     private $_aol_version '';
0146
0147     const BROWSER_UNKNOWN = 'unknown';
0148     const VERSION_UNKNOWN = 'unknown';
0149
0150     const BROWSER_OPERA = 'Opera';// http://www.opera.com/
0151     const BROWSER_OPERA_MINI = 'Opera Mini';  // http://www.opera.com/mini/
0152     const BROWSER_WEBTV = 'WebTV';// http://www.webtv.net/pc/
0153     const BROWSER_IE = 'Internet Explorer';   // http://www.microsoft.com/ie/
0154     const BROWSER_POCKET_IE = 'Pocket Internet Explorer'// http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
0155     const BROWSER_KONQUEROR = 'Konqueror';// http://www.konqueror.org/
0156     const BROWSER_ICAB = 'iCab';  // http://www.icab.de/
0157     const BROWSER_OMNIWEB = 'OmniWeb';// http://www.omnigroup.com/applications/omniweb/
0158     const BROWSER_FIREBIRD = 'Firebird';  // http://www.ibphoenix.com/
0159     const BROWSER_FIREFOX = 'Firefox';// http://www.mozilla.com/en-US/firefox/firefox.html
0160     const BROWSER_ICEWEASEL = 'Iceweasel';// http://www.geticeweasel.org/
0161     const BROWSER_SHIRETOKO = 'Shiretoko';// http://wiki.mozilla.org/Projects/shiretoko
0162     const BROWSER_MOZILLA = 'Mozilla';// http://www.mozilla.com/en-US/
0163     const BROWSER_AMAYA = 'Amaya';// http://www.w3.org/Amaya/
0164     const BROWSER_LYNX = 'Lynx';  // http://en.wikipedia.org/wiki/Lynx
0165     const BROWSER_SAFARI = 'Safari';  // http://apple.com
0166     const BROWSER_IPHONE = 'iPhone';  // http://apple.com
0167     const BROWSER_IPOD = 'iPod';  // http://apple.com
0168     const BROWSER_IPAD = 'iPad';  // http://apple.com
0169     const BROWSER_CHROME = 'Chrome';  // http://www.google.com/chrome
0170     const BROWSER_ANDROID = 'Android';// http://www.android.com/
0171     const BROWSER_GOOGLEBOT = 'GoogleBot';// http://en.wikipedia.org/wiki/Googlebot
0172     const BROWSER_SLURP = 'Yahoo! Slurp'// http://en.wikipedia.org/wiki/Yahoo!_Slurp
0173     const BROWSER_W3CVALIDATOR = 'W3C Validator'// http://validator.w3.org/
0174     const BROWSER_BLACKBERRY = 'BlackBerry';  // http://www.blackberry.com/
0175     const BROWSER_ICECAT = 'IceCat';  // http://en.wikipedia.org/wiki/GNU_IceCat
0176     const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser';// http://en.wikipedia.org/wiki/Web_Browser_for_S60
0177     const BROWSER_NOKIA = 'Nokia Browser';// * all other WAP-based browsers on the Nokia Platform
0178     const BROWSER_MSN = 'MSN Browser';// http://explorer.msn.com/
0179     const BROWSER_MSNBOT = 'MSN Bot'// http://search.msn.com/msnbot.htm
0180       // http://en.wikipedia.org/wiki/Msnbot  (used for Bing as well)
0181     
0182     const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator';  // http://browser.netscape.com/ (DEPRECATED)
0183     const BROWSER_GALEON = 'Galeon';  // http://galeon.sourceforge.net/ (DEPRECATED)
0184     const BROWSER_NETPOSITIVE = 'NetPositive';// http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
0185     const BROWSER_PHOENIX = 'Phoenix';// http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
0186
0187     const PLATFORM_UNKNOWN = 'unknown';
0188     const PLATFORM_WINDOWS = 'Windows';
0189     const PLATFORM_WINDOWS_CE = 'Windows CE';
0190     const PLATFORM_APPLE = 'Apple';
0191     const PLATFORM_LINUX = 'Linux';
0192     const PLATFORM_OS2 = 'OS/2';
0193     const PLATFORM_BEOS = 'BeOS';
0194     const PLATFORM_IPHONE = 'iPhone';
0195     const PLATFORM_IPOD = 'iPod';
0196     const PLATFORM_IPAD = 'iPad';
0197     const PLATFORM_BLACKBERRY = 'BlackBerry';
0198     const PLATFORM_NOKIA = 'Nokia';
0199     const PLATFORM_FREEBSD = 'FreeBSD';
0200     const PLATFORM_OPENBSD = 'OpenBSD';
0201     const PLATFORM_NETBSD = 'NetBSD';
0202     const PLATFORM_SUNOS = 'SunOS';
0203     const PLATFORM_OPENSOLARIS = 'OpenSolaris';
0204     const PLATFORM_ANDROID = 'Android';
0205     
0206     const OPERATING_SYSTEM_UNKNOWN = 'unknown';
0207
0208     public function Browser($useragent="") {
0209         $this->reset();
0210         if$useragent != "" ) {
0211             $this->setUserAgent($useragent);
0212         }
0213         else {
0214             $this->determine();
0215         }
0216     }
0217
0218     /**
0219     * Reset all properties
0220     */
0221     public function reset() {
0222         $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
0223         $this->_browser_name = self::BROWSER_UNKNOWN;
0224         $this->_version = self::VERSION_UNKNOWN;
0225         $this->_platform = self::PLATFORM_UNKNOWN;
0226         $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
0227         $this->_is_aol = false;
0228         $this->_is_mobile = false;
0229         $this->_is_robot = false;
0230         $this->_aol_version = self::VERSION_UNKNOWN;
0231     }
0232
0233     /**
0234     * Check to see if the specific browser is valid
0235     * @param string $browserName
0236     * @return True if the browser is the specified browser
0237     */
0238     function isBrowser($browserName) { return( 0 == strcasecmp($this->_browser_name, trim($browserName))); }
0239
0240     /**
0241     * The name of the browser.  All return types are from the class contants
0242     * @return string Name of the browser
0243     */
0244     public function getBrowser() { return $this->_browser_name; }
0245     /**
0246     * Set the name of the browser
0247     * @param $browser The name of the Browser
0248     */
0249     public function setBrowser($browser) { return $this->_browser_name = $browser; }
0250     /**
0251     * The name of the platform.  All return types are from the class contants
0252     * @return string Name of the browser
0253     */
0254     public function getPlatform() { return $this->_platform; }
0255     /**
0256     * Set the name of the platform
0257     * @param $platform The name of the Platform
0258     */
0259     public function setPlatform($platform) { return $this->_platform = $platform; }
0260     /**
0261     * The version of the browser.
0262     * @return string Version of the browser (will only contain alpha-numeric characters and a period)
0263     */
0264     public function getVersion() { return $this->_version; }
0265     /**
0266     * Set the version of the browser
0267     * @param $version The version of the Browser
0268     */
0269     public function setVersion($version) { $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/','',$version); }
0270     /**
0271     * The version of AOL.
0272     * @return string Version of AOL (will only contain alpha-numeric characters and a period)
0273     */
0274     public function getAolVersion() { return $this->_aol_version; }
0275     /**
0276     * Set the version of AOL
0277     * @param $version The version of AOL
0278     */
0279     public function setAolVersion($version) { $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/','',$version); }
0280     /**
0281     * Is the browser from AOL?
0282     * @return boolean True if the browser is from AOL otherwise false
0283     */
0284     public function isAol() { return $this->_is_aol; }
0285     /**
0286     * Is the browser from a mobile device?
0287     * @return boolean True if the browser is from a mobile device otherwise false
0288     */
0289     public function isMobile() { return $this->_is_mobile; }
0290     /**
0291     * Is the browser from a robot (ex Slurp,GoogleBot)?
0292     * @return boolean True if the browser is from a robot otherwise false
0293     */
0294     public function isRobot() { return $this->_is_robot; }
0295     /**
0296     * Set the browser to be from AOL
0297     * @param $isAol
0298     */
0299     public function setAol($isAol) { $this->_is_aol = $isAol; }
0300     /**
0301      * Set the Browser to be mobile
0302      * @param boolean $value is the browser a mobile brower or not
0303      */
0304     protected function setMobile($value=true) { $this->_is_mobile = $value; }
0305     /**
0306      * Set the Browser to be a robot
0307      * @param boolean $value is the browser a robot or not
0308      */
0309     protected function setRobot($value=true) { $this->_is_robot = $value; }
0310     /**
0311     * Get the user agent value in use to determine the browser
0312     * @return string The user agent from the HTTP header
0313     */
0314     public function getUserAgent() { return $this->_agent; }
0315     /**
0316     * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
0317     * @param $agent_string The value for the User Agent
0318     */
0319     public function setUserAgent($agent_string) {
0320         $this->reset();
0321         $this->_agent = $agent_string;
0322         $this->determine();
0323     }
0324     /**
0325      * Used to determine if the browser is actually "chromeframe"
0326      * @since 1.7
0327      * @return boolean True if the browser is using chromeframe
0328      */
0329     public function isChromeFrame() {
0330         returnstrpos($this->_agent,"chromeframe") !== false );
0331     }
0332     /**
0333     * Returns a formatted string with a summary of the details of the browser.
0334     * @return string formatted string with a summary of the browser
0335     */
0336     public function __toString() {
0337         return "<strong>Browser Name:</strong>{$this->getBrowser()}<br/>\n" .
0338            "<strong>Browser Version:</strong>{$this->getVersion()}<br/>\n" .
0339            "<strong>Browser User Agent String:</strong>{$this->getUserAgent()}<br/>\n" .
0340            "<strong>Platform:</strong>{$this->getPlatform()}<br/>";
0341     }
0342     /**
0343      * Protected routine to calculate and determine what the browser is in use (including platform)
0344      */
0345     protected function determine() {
0346         $this->checkPlatform();
0347         $this->checkBrowsers();
0348         $this->checkForAol();
0349     }
0350     /**
0351      * Protected routine to determine the browser type
0352      * @return boolean True if the browser was detected otherwise false
0353      */
0354      protected function checkBrowsers() {
0355         return (
0356             // well-known, well-used
0357             // Special Notes:
0358             // (1) Opera must be checked before FireFox due to the odd
0359             // user agents used in some older versions of Opera
0360             // (2) WebTV is strapped onto Internet Explorer so we must
0361             // check for WebTV before IE
0362             // (3) (deprecated) Galeon is based on Firefox and needs to be
0363             // tested before Firefox is tested
0364             // (4) OmniWeb is based on Safari so OmniWeb check must occur
0365             // before Safari
0366             // (5) Netscape 9+ is based on Firefox so Netscape checks
0367             // before FireFox are necessary
0368             $this->checkBrowserWebTv() ||
0369             $this->checkBrowserInternetExplorer() ||
0370             $this->checkBrowserOpera() ||
0371             $this->checkBrowserGaleon() ||
0372             $this->checkBrowserNetscapeNavigator9Plus() ||
0373             $this->checkBrowserFirefox() ||
0374             $this->checkBrowserChrome() ||
0375             $this->checkBrowserOmniWeb() ||
0376
0377             // common mobile
0378             $this->checkBrowserAndroid() ||
0379             $this->checkBrowseriPad() ||
0380             $this->checkBrowseriPod() ||
0381             $this->checkBrowseriPhone() ||
0382             $this->checkBrowserBlackBerry() ||
0383             $this->checkBrowserNokia() ||
0384
0385             // common bots
0386             $this->checkBrowserGoogleBot() ||
0387             $this->checkBrowserMSNBot() ||
0388             $this->checkBrowserSlurp() ||
0389
0390             // WebKit base check (post mobile and others)
0391             $this->checkBrowserSafari() ||
0392             
0393             // everyone else
0394             $this->checkBrowserNetPositive() ||
0395             $this->checkBrowserFirebird() ||
0396             $this->checkBrowserKonqueror() ||
0397             $this->checkBrowserIcab() ||
0398             $this->checkBrowserPhoenix() ||
0399             $this->checkBrowserAmaya() ||
0400             $this->checkBrowserLynx() ||
0401             $this->checkBrowserShiretoko() ||
0402             $this->checkBrowserIceCat() ||
0403             $this->checkBrowserW3CValidator() ||
0404             $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
0405         );
0406     }
0407
0408     /**
0409      * Determine if the user is using a BlackBerry (last updated 1.7)
0410      * @return boolean True if the browser is the BlackBerry browser otherwise false
0411      */
0412     protected function checkBrowserBlackBerry() {
0413         ifstripos($this->_agent,'blackberry') !== false ) {
0414             $aresult explode("/",stristr($this->_agent,"BlackBerry"));
0415             $aversion explode(' ',$aresult[1]);
0416             $this->setVersion($aversion[0]);
0417             $this->_browser_name = self::BROWSER_BLACKBERRY;
0418             $this->setMobile(true);
0419             return true;
0420         }
0421         return false;
0422     }
0423
0424     /**
0425      * Determine if the user is using an AOL User Agent (last updated 1.7)
0426      * @return boolean True if the browser is from AOL otherwise false
0427      */
0428     protected function checkForAol() {
0429             $this->setAol(false);
0430             $this->setAolVersion(self::VERSION_UNKNOWN);
0431
0432             ifstripos($this->_agent,'aol') !== false ) {
0433             $aversion explode(' ',stristr($this->_agent, 'AOL'));
0434             $this->setAol(true);
0435             $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i'''$aversion[1]));
0436             return true;
0437         }
0438         return false;
0439     }
0440
0441     /**
0442      * Determine if the browser is the GoogleBot or not (last updated 1.7)
0443      * @return boolean True if the browser is the GoogletBot otherwise false
0444      */
0445     protected function checkBrowserGoogleBot() {
0446         ifstripos($this->_agent,'googlebot') !== false ) {
0447                 $aresult explode('/',stristr($this->_agent,'googlebot'));
0448                 $aversion explode(' ',$aresult[1]);
0449                 $this->setVersion(str_replace(';','',$aversion[0]));
0450                 $this->_browser_name = self::BROWSER_GOOGLEBOT;
0451                 $this->setRobot(true);
0452                 return true;
0453         }
0454         return false;
0455     }
0456
0457         /**
0458      * Determine if the browser is the MSNBot or not (last updated 1.9)
0459      * @return boolean True if the browser is the MSNBot otherwise false
0460      */
0461         protected function checkBrowserMSNBot() {
0462             ifstripos($this->_agent,"msnbot") !== false ) {
0463                 $aresult explode("/",stristr($this->_agent,"msnbot"));
0464                 $aversion explode(" ",$aresult[1]);
0465                 $this->setVersion(str_replace(";","",$aversion[0]));
0466                 $this->_browser_name = self::BROWSER_MSNBOT;
0467                 $this->setRobot(true);
0468                 return true;
0469             }
0470             return false;
0471         }  
0472     
0473     /**
0474      * Determine if the browser is the W3C Validator or not (last updated 1.7)
0475      * @return boolean True if the browser is the W3C Validator otherwise false
0476      */
0477     protected function checkBrowserW3CValidator() {
0478         ifstripos($this->_agent,'W3C-checklink') !== false ) {
0479             $aresult explode('/',stristr($this->_agent,'W3C-checklink'));
0480             $aversion explode(' ',$aresult[1]);
0481             $this->setVersion($aversion[0]);
0482             $this->_browser_name = self::BROWSER_W3CVALIDATOR;
0483             return true;
0484         }
0485         else ifstripos($this->_agent,'W3C_Validator') !== false ) {
0486                 // Some of the Validator versions do not delineate w/ a slash - add it back in
0487                 $ua str_replace("W3C_Validator ""W3C_Validator/"$this->_agent);
0488             $aresult explode('/',stristr($ua,'W3C_Validator'));
0489             $aversion explode(' ',$aresult[1]);
0490             $this->setVersion($aversion[0]);
0491             $this->_browser_name = self::BROWSER_W3CVALIDATOR;
0492             return true;
0493         }
0494         return false;
0495     }
0496
0497     /**
0498      * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
0499      * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
0500      */
0501     protected function checkBrowserSlurp() {
0502         ifstripos($this->_agent,'slurp') !== false ) {
0503             $aresult explode('/',stristr($this->_agent,'Slurp'));
0504             $aversion explode(' ',$aresult[1]);
0505             $this->setVersion($aversion[0]);
0506             $this->_browser_name = self::BROWSER_SLURP;
0507                 $this->setRobot(true);
0508                 $this->setMobile(false);
0509             return true;
0510         }
0511         return false;
0512     }
0513
0514     /**
0515      * Determine if the browser is Internet Explorer or not (last updated 1.7)
0516      * @return boolean True if the browser is Internet Explorer otherwise false
0517      */
0518     protected function checkBrowserInternetExplorer() {
0519
0520         // Test for v1 - v1.5 IE
0521         ifstripos($this->_agent,'microsoft internet explorer') !== false ) {
0522             $this->setBrowser(self::BROWSER_IE);
0523             $this->setVersion('1.0');
0524             $aresult stristr($this->_agent, '/');
0525             if( preg_match('/308|425|426|474|0b1/i'$aresult) ) {
0526                 $this->setVersion('1.5');
0527             }
0528                 return true;
0529         }
0530         // Test for versions > 1.5
0531         else ifstripos($this->_agent,'msie') !== false && stripos($this->_agent,'opera') === false ) {
0532             // See if the browser is the odd MSN Explorer
0533             ifstripos($this->_agent,'msnb') !== false ) {
0534                 $aresult explode(' ',stristr(str_replace(';','; ',$this->_agent),'MSN'));
0535                 $this->setBrowser( self::BROWSER_MSN );
0536                 $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
0537                 return true;
0538             }
0539             $aresult explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie'));
0540             $this->setBrowser( self::BROWSER_IE );
0541             $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
0542             return true;
0543         }
0544         // Test for Pocket IE
0545         else ifstripos($this->_agent,'mspie') !== false || stripos($this->_agent,'pocket') !== false ) {
0546             $aresult explode(' ',stristr($this->_agent,'mspie'));
0547             $this->setPlatform( self::PLATFORM_WINDOWS_CE );
0548             $this->setBrowser( self::BROWSER_POCKET_IE );
0549             $this->setMobile(true);
0550
0551             ifstripos($this->_agent,'mspie') !== false ) {
0552                 $this->setVersion($aresult[1]);
0553             }
0554             else {
0555                 $aversion explode('/',$this->_agent);
0556                 $this->setVersion($aversion[1]);
0557             }
0558             return true;
0559         }
0560             return false;
0561     }
0562
0563     /**
0564      * Determine if the browser is Opera or not (last updated 1.7)
0565      * @return boolean True if the browser is Opera otherwise false
0566      */
0567     protected function checkBrowserOpera() {
0568         ifstripos($this->_agent,'opera mini') !== false ) {
0569             $resultant stristr($this->_agent, 'opera mini');
0570             if( preg_match('/\//',$resultant) ) {
0571                 $aresult explode('/',$resultant);
0572                 $aversion explode(' ',$aresult[1]);
0573                 $this->setVersion($aversion[0]);
0574                 }
0575             else {
0576                 $aversion explode(' ',stristr($resultant,'opera mini'));
0577                 $this->setVersion($aversion[1]);
0578             }
0579             $this->_browser_name = self::BROWSER_OPERA_MINI;
0580                 $this->setMobile(true);
0581                 return true;
0582         }
0583         else ifstripos($this->_agent,'opera') !== false ) {
0584             $resultant stristr($this->_agent, 'opera');
0585             if( preg_match('/Version\/(10.*)$/',$resultant,$matches) ) {
0586                 $this->setVersion($matches[1]);
0587             }
0588             else if( preg_match('/\//',$resultant) ) {
0589                 $aresult explode('/',str_replace("("," ",$resultant));
0590                 $aversion explode(' ',$aresult[1]);
0591                 $this->setVersion($aversion[0]);
0592             }
0593             else {
0594                 $aversion explode(' ',stristr($resultant,'opera'));
0595                 $this->setVersion(isset($aversion[1])?$aversion[1]:"");
0596             }
0597             $this->_browser_name = self::BROWSER_OPERA;
0598             return true;
0599         }
0600             return false;
0601     }
0602
0603     /**
0604      * Determine if the browser is Chrome or not (last updated 1.7)
0605      * @return boolean True if the browser is Chrome otherwise false
0606      */
0607     protected function checkBrowserChrome() {
0608         ifstripos($this->_agent,'Chrome') !== false ) {
0609             $aresult explode('/',stristr($this->_agent,'Chrome'));
0610             $aversion explode(' ',$aresult[1]);
0611             $this->setVersion($aversion[0]);
0612             $this->setBrowser(self::BROWSER_CHROME);
0613             return true;
0614         }
0615         return false;
0616     }
0617
0618
0619     /**
0620      * Determine if the browser is WebTv or not (last updated 1.7)
0621      * @return boolean True if the browser is WebTv otherwise false
0622      */
0623     protected function checkBrowserWebTv() {
0624         ifstripos($this->_agent,'webtv') !== false ) {
0625             $aresult explode('/',stristr($this->_agent,'webtv'));
0626             $aversion explode(' ',$aresult[1]);
0627             $this->setVersion($aversion[0]);
0628             $this->setBrowser(self::BROWSER_WEBTV);
0629             return true;
0630         }
0631         return false;
0632     }
0633
0634     /**
0635      * Determine if the browser is NetPositive or not (last updated 1.7)
0636      * @return boolean True if the browser is NetPositive otherwise false
0637      */
0638     protected function checkBrowserNetPositive() {
0639         ifstripos($this->_agent,'NetPositive') !== false ) {
0640             $aresult explode('/',stristr($this->_agent,'NetPositive'));
0641             $aversion explode(' ',$aresult[1]);
0642             $this->setVersion(str_replace(array('(',')',';'),'',$aversion[0]));
0643             $this->setBrowser(self::BROWSER_NETPOSITIVE);
0644             return true;
0645         }
0646         return false;
0647     }
0648
0649     /**
0650      * Determine if the browser is Galeon or not (last updated 1.7)
0651      * @return boolean True if the browser is Galeon otherwise false
0652      */
0653     protected function checkBrowserGaleon() {
0654         ifstripos($this->_agent,'galeon') !== false ) {
0655             $aresult explode(' ',stristr($this->_agent,'galeon'));
0656             $aversion explode('/',$aresult[0]);
0657             $this->setVersion($aversion[1]);
0658             $this->setBrowser(self::BROWSER_GALEON);
0659             return true;
0660         }
0661         return false;
0662     }
0663
0664     /**
0665      * Determine if the browser is Konqueror or not (last updated 1.7)
0666      * @return boolean True if the browser is Konqueror otherwise false
0667      */
0668     protected function checkBrowserKonqueror() {
0669         ifstripos($this->_agent,'Konqueror') !== false ) {
0670             $aresult explode(' ',stristr($this->_agent,'Konqueror'));
0671             $aversion explode('/',$aresult[0]);
0672             $this->setVersion($aversion[1]);
0673             $this->setBrowser(self::BROWSER_KONQUEROR);
0674             return true;
0675         }
0676         return false;
0677     }
0678
0679     /**
0680      * Determine if the browser is iCab or not (last updated 1.7)
0681      * @return boolean True if the browser is iCab otherwise false
0682      */
0683     protected function checkBrowserIcab() {
0684         ifstripos($this->_agent,'icab') !== false ) {
0685             $aversion explode(' ',stristr(str_replace('/',' ',$this->_agent),'icab'));
0686             $this->setVersion($aversion[1]);
0687             $this->setBrowser(self::BROWSER_ICAB);
0688             return true;
0689         }
0690         return false;
0691     }
0692
0693     /**
0694      * Determine if the browser is OmniWeb or not (last updated 1.7)
0695      * @return boolean True if the browser is OmniWeb otherwise false
0696      */
0697     protected function checkBrowserOmniWeb() {
0698         ifstripos($this->_agent,'omniweb') !== false ) {
0699             $aresult explode('/',stristr($this->_agent,'omniweb'));
0700             $aversion explode(' ',isset($aresult[1])?$aresult[1]:"");
0701             $this->setVersion($aversion[0]);
0702             $this->setBrowser(self::BROWSER_OMNIWEB);
0703             return true;
0704         }
0705         return false;
0706     }
0707
0708     /**
0709      * Determine if the browser is Phoenix or not (last updated 1.7)
0710      * @return boolean True if the browser is Phoenix otherwise false
0711      */
0712     protected function checkBrowserPhoenix() {
0713         ifstripos($this->_agent,'Phoenix') !== false ) {
0714             $aversion explode('/',stristr($this->_agent,'Phoenix'));
0715             $this->setVersion($aversion[1]);
0716             $this->setBrowser(self::BROWSER_PHOENIX);
0717             return true;
0718         }
0719         return false;
0720     }
0721
0722     /**
0723      * Determine if the browser is Firebird or not (last updated 1.7)
0724      * @return boolean True if the browser is Firebird otherwise false
0725      */
0726     protected function checkBrowserFirebird() {
0727         ifstripos($this->_agent,'Firebird') !== false ) {
0728             $aversion explode('/',stristr($this->_agent,'Firebird'));
0729             $this->setVersion($aversion[1]);
0730             $this->setBrowser(self::BROWSER_FIREBIRD);
0731                 return true;
0732         }
0733         return false;
0734     }
0735
0736     /**
0737      * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
0738          * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
0739      * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
0740      */
0741     protected function checkBrowserNetscapeNavigator9Plus() {
0742         ifstripos($this->_agent,'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i',$this->_agent,$matches) ) {
0743             $this->setVersion($matches[1]);
0744             $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
0745             return true;
0746         }
0747         else ifstripos($this->_agent,'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i',$this->_agent,$matches) ) {
0748             $this->setVersion($matches[1]);
0749             $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
0750             return true;
0751         }
0752         return false;
0753     }
0754
0755     /**
0756      * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
0757      * @return boolean True if the browser is Shiretoko otherwise false
0758      */
0759     protected function checkBrowserShiretoko() {
0760         ifstripos($this->_agent,'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i',$this->_agent,$matches) ) {
0761             $this->setVersion($matches[1]);
0762             $this->setBrowser(self::BROWSER_SHIRETOKO);
0763             return true;
0764         }
0765         return false;
0766     }
0767
0768     /**
0769      * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
0770      * @return boolean True if the browser is Ice Cat otherwise false
0771      */
0772     protected function checkBrowserIceCat() {
0773         ifstripos($this->_agent,'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i',$this->_agent,$matches) ) {
0774             $this->setVersion($matches[1]);
0775             $this->setBrowser(self::BROWSER_ICECAT);
0776             return true;
0777         }
0778         return false;
0779     }
0780
0781     /**
0782      * Determine if the browser is Nokia or not (last updated 1.7)
0783      * @return boolean True if the browser is Nokia otherwise false
0784      */
0785     protected function checkBrowserNokia() {
0786         if( preg_match("/Nokia([^\/]+)\/([^ SP]+)/i",$this->_agent,$matches) ) {
0787             $this->setVersion($matches[2]);
0788                 ifstripos($this->_agent,'Series60') !== false || strpos($this->_agent,'S60') !== false ) {
0789                     $this->setBrowser(self::BROWSER_NOKIA_S60);
0790                 }
0791                 else {
0792                     $this->setBrowser( self::BROWSER_NOKIA );
0793                 }
0794             $this->setMobile(true);
0795             return true;
0796         }
0797             return false;
0798     }
0799
0800     /**
0801      * Determine if the browser is Firefox or not (last updated 1.7)
0802      * @return boolean True if the browser is Firefox otherwise false
0803      */
0804     protected function checkBrowserFirefox() {
0805         ifstripos($this->_agent,'safari') === false ) {
0806                 if( preg_match("/Firefox[\/ \(]([^ ;\)]+)/i",$this->_agent,$matches) ) {
0807                     $this->setVersion($matches[1]);
0808                     $this->setBrowser(self::BROWSER_FIREFOX);
0809                     return true;
0810                 }
0811                 else if( preg_match("/Firefox$/i",$this->_agent,$matches) ) {
0812                     $this->setVersion("");
0813                     $this->setBrowser(self::BROWSER_FIREFOX);
0814                     return true;
0815                 }
0816             }
0817         return false;
0818     }
0819
0820         /**
0821      * Determine if the browser is Firefox or not (last updated 1.7)
0822      * @return boolean True if the browser is Firefox otherwise false
0823      */
0824     protected function checkBrowserIceweasel() {
0825             ifstripos($this->_agent,'Iceweasel') !== false ) {
0826                 $aresult explode('/',stristr($this->_agent,'Iceweasel'));
0827                 $aversion explode(' ',$aresult[1]);
0828                 $this->setVersion($aversion[0]);
0829                 $this->setBrowser(self::BROWSER_ICEWEASEL);
0830                 return true;
0831             }
0832             return false;
0833         }
0834     /**
0835      * Determine if the browser is Mozilla or not (last updated 1.7)
0836      * @return boolean True if the browser is Mozilla otherwise false
0837      */
0838     protected function checkBrowserMozilla() {
0839         ifstripos($this->_agent,'mozilla') !== false  && preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent) && stripos($this->_agent,'netscape') === false) {
0840             $aversion explode(' ',stristr($this->_agent,'rv:'));
0841             preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent,$aversion);
0842             $this->setVersion(str_replace('rv:','',$aversion[0]));
0843             $this->setBrowser(self::BROWSER_MOZILLA);
0844             return true;
0845         }
0846         else ifstripos($this->_agent,'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i',$this->_agent) && stripos($this->_agent,'netscape') === false ) {
0847             $aversion explode('',stristr($this->_agent,'rv:'));
0848             $this->setVersion(str_replace('rv:','',$aversion[0]));
0849             $this->setBrowser(self::BROWSER_MOZILLA);
0850             return true;
0851         }
0852         else ifstripos($this->_agent,'mozilla') !== false  && preg_match('/mozilla\/([^ ]*)/i',$this->_agent,$matches) && stripos($this->_agent,'netscape') === false ) {
0853             $this->setVersion($matches[1]);
0854             $this->setBrowser(self::BROWSER_MOZILLA);
0855             return true;
0856         }
0857             return false;
0858     }
0859
0860     /**
0861      * Determine if the browser is Lynx or not (last updated 1.7)
0862      * @return boolean True if the browser is Lynx otherwise false
0863      */
0864     protected function checkBrowserLynx()
0865     {
0866         ifstripos($this->_agent,'lynx') !== false ) {
0867             $aresult explode('/',stristr($this->_agent,'Lynx'));
0868             $aversion explode(' ',(isset($aresult[1])?$aresult[1]:""));
0869             $this->setVersion($aversion[0]);
0870             $this->setBrowser(self::BROWSER_LYNX);
0871             return true;
0872         }
0873         return false;
0874     }
0875
0876     /**
0877      * Determine if the browser is Amaya or not (last updated 1.7)
0878      * @return boolean True if the browser is Amaya otherwise false
0879      */
0880     protected function checkBrowserAmaya()
0881     {
0882         ifstripos($this->_agent,'amaya') !== false ) {
0883             $aresult explode('/',stristr($this->_agent,'Amaya'));
0884             $aversion explode(' ',$aresult[1]);
0885             $this->setVersion($aversion[0]);
0886             $this->setBrowser(self::BROWSER_AMAYA);
0887             return true;
0888         }
0889         return false;
0890     }
0891
0892     /**
0893      * Determine if the browser is Safari or not (last updated 1.7)
0894      * @return boolean True if the browser is Safari otherwise false
0895      */
0896     protected function checkBrowserSafari()
0897     {
0898         ifstripos($this->_agent,'Safari') !== false && stripos($this->_agent,'iPhone') === false && stripos($this->_agent,'iPod') === false ) {
0899             $aresult explode('/',stristr($this->_agent,'Version'));
0900             if( isset($aresult[1]) ) {
0901                 $aversion explode(' ',$aresult[1]);
0902                 $this->setVersion($aversion[0]);
0903             }
0904             else $this->setVersion(self::VERSION_UNKNOWN);
0905             $this->setBrowser(self::BROWSER_SAFARI);
0906             return true;
0907         }
0908         return false;
0909     }
0910
0911     /**
0912      * Determine if the browser is iPhone or not (last updated 1.7)
0913      * @return boolean True if the browser is iPhone otherwise false
0914      */
0915     protected function checkBrowseriPhone()
0916     {
0917         ifstripos($this->_agent,'iPhone') !== false ) {
0918             $aresult explode('/',stristr($this->_agent,'Version'));
0919             if( isset($aresult[1]) ) {
0920                 $aversion explode(' ',$aresult[1]);
0921                 $this->setVersion($aversion[0]);
0922             }
0923             else $this->setVersion(self::VERSION_UNKNOWN);
0924             $this->setMobile(true);
0925             $this->setBrowser(self::BROWSER_IPHONE);
0926             return true;
0927         }
0928         return false;
0929     }
0930
0931     /**
0932      * Determine if the browser is iPod or not (last updated 1.7)
0933      * @return boolean True if the browser is iPod otherwise false
0934      */
0935     protected function checkBrowseriPad()
0936     {
0937         ifstripos($this->_agent,'iPad') !== false ) {
0938             $aresult explode('/',stristr($this->_agent,'Version'));
0939             if( isset($aresult[1]) ) {
0940                 $aversion explode(' ',$aresult[1]);
0941                 $this->setVersion($aversion[0]);
0942             }
0943             else $this->setVersion(self::VERSION_UNKNOWN);
0944             $this->setMobile(true);
0945             $this->setBrowser(self::BROWSER_IPAD);
0946             return true;
0947         }
0948         return false;
0949     }
0950
0951     /**
0952      * Determine if the browser is iPod or not (last updated 1.7)
0953      * @return boolean True if the browser is iPod otherwise false
0954      */
0955     protected function checkBrowseriPod()
0956     {
0957         ifstripos($this->_agent,'iPod') !== false ) {
0958             $aresult explode('/',stristr($this->_agent,'Version'));
0959             if( isset($aresult[1]) ) {
0960                 $aversion explode(' ',$aresult[1]);
0961                 $this->setVersion($aversion[0]);
0962             }
0963             else $this->setVersion(self::VERSION_UNKNOWN);
0964             $this->setMobile(true);
0965             $this->setBrowser(self::BROWSER_IPOD);
0966             return true;
0967         }
0968         return false;
0969     }
0970
0971     /**
0972      * Determine if the browser is Android or not (last updated 1.7)
0973      * @return boolean True if the browser is Android otherwise false
0974      */
0975     protected function checkBrowserAndroid()
0976     {
0977         ifstripos($this->_agent,'Android') !== false ) {
0978             $aresult explode(' ',stristr($this->_agent,'Android'));
0979             if( isset($aresult[1]) ) {
0980                 $aversion explode(' ',$aresult[1]);
0981                 $this->setVersion($aversion[0]);
0982             }
0983             else $this->setVersion(self::VERSION_UNKNOWN);
0984             $this->setMobile(true);
0985             $this->setBrowser(self::BROWSER_ANDROID);
0986             return true;
0987         }
0988         return false;
0989     }
0990
0991     /**
0992      * Determine the user's platform (last updated 1.7)
0993      */
0994     protected function checkPlatform()
0995     {
0996         ifstripos($this->_agent, 'windows') !== false ) $this->_platform = self::PLATFORM_WINDOWS;
0997         else ifstripos($this->_agent, 'iPad') !== false ) $this->_platform = self::PLATFORM_IPAD;
0998         else ifstripos($this->_agent, 'iPod') !== false ) $this->_platform = self::PLATFORM_IPOD;
0999         else ifstripos($this->_agent, 'iPhone') !== false ) $this->_platform = self::PLATFORM_IPHONE;
1000         elseifstripos($this->_agent, 'mac') !== false ) $this->_platform = self::PLATFORM_APPLE;
1001         elseifstripos($this->_agent, 'android') !== false ) $this->_platform = self::PLATFORM_ANDROID;
1002         elseifstripos($this->_agent, 'linux') !== false ) $this->_platform = self::PLATFORM_LINUX;
1003         else ifstripos($this->_agent, 'Nokia') !== false ) $this->_platform = self::PLATFORM_NOKIA;
1004         else ifstripos($this->_agent, 'BlackBerry') !== false ) $this->_platform = self::PLATFORM_BLACKBERRY;
1005         elseifstripos($this->_agent,'FreeBSD') !== false ) $this->_platform = self::PLATFORM_FREEBSD;
1006         elseifstripos($this->_agent,'OpenBSD') !== false ) $this->_platform = self::PLATFORM_OPENBSD;
1007         elseifstripos($this->_agent,'NetBSD') !== false ) $this->_platform = self::PLATFORM_NETBSD;
1008         elseifstripos($this->_agent, 'OpenSolaris') !== false ) $this->_platform = self::PLATFORM_OPENSOLARIS;
1009         elseifstripos($this->_agent, 'SunOS') !== false ) $this->_platform = self::PLATFORM_SUNOS;
1010         elseifstripos($this->_agent, 'OS\/2') !== false ) $this->_platform = self::PLATFORM_OS2;
1011         elseifstripos($this->_agent, 'BeOS') !== false ) $this->_platform = self::PLATFORM_BEOS;
1012         elseifstripos($this->_agent, 'win') !== false ) $this->_platform = self::PLATFORM_WINDOWS;
1013     }
1014 }

这个类的使用方法也很简单,如下:

1 $obj_browser new Browser; //创建一个此类的一个实例
2 $obj_browser->getBrowser(); //调用相关函数,获取浏览器名称
3 $obj_browser->getPlatform(); //调用相关函数,获取系统名称
4 $obj_browser->isMobile(); //判断来访者所用设备是iPhone、iPad或者电脑(PC)

ok,至此通过 php 判断浏览器类型的方法已经总结完了,三种办法,但如果要求精度不是那么高的话,第一种完全可以了,第二种,第三种办法实在有点太过精细了而且靠谱度未能确定复杂度却显而易见。

打赏此文

如果您觉得本站的内容对您有所帮助,您可以扫描下面的二维码小额支付请我喝杯茶,感谢!打赏记录
支付宝
微信
承诺:凡打赏捐助的朋友,留言备注自己的邮箱,在打赏捐助时间点的6个月内,本站会每周邮件推送原创专业技术博文,供大家学习和参考!

留下评论

All fields marked (*) are required