PageRenderTime 84ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/browser.php

https://github.com/scottpoulin/jigoshop
PHP | 1078 lines | 641 code | 52 blank | 385 comment | 101 complexity | 420d9ab55a67aeda484d211c44a978fb MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Modified to work for Jigoshop by
  4. * Chris Christoff on 8/2/2012
  5. * Changes: Removed the browser string return and added spacing. Also removed return HTML formatting.
  6. *
  7. * Modified to add formatted User Agent string for Jigoshop System Info by
  8. * Chris Christoff on 8/4/2012
  9. * Changes: Split user string and add formatting so we can print a nicely
  10. * formatted user agent string on the Jigoshop System Info
  11. *
  12. * File: Browser.php
  13. * Author: Chris Schuld (http://chrisschuld.com/)
  14. * Last Modified: August 20th, 2010
  15. * @version 1.9
  16. * @package PegasusPHP
  17. *
  18. * Copyright (C) 2008-2010 Chris Schuld (chris@chrisschuld.com)
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details at:
  29. * http://www.gnu.org/copyleft/gpl.html
  30. *
  31. *
  32. * Typical Usage:
  33. *
  34. * $browser = new Browser();
  35. * if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
  36. * echo 'You have FireFox version 2 or greater';
  37. * }
  38. *
  39. * User Agents Sampled from: http://www.useragentstring.com/
  40. *
  41. * This implementation is based on the original work from Gary White
  42. * http://apptools.com/phptools/browser/
  43. *
  44. * UPDATES:
  45. *
  46. * 2010-08-20 (v1.9):
  47. * + Added MSN Explorer Browser (legacy)
  48. * + Added Bing/MSN Robot (Thanks Rob MacDonald)
  49. * + Added the Android Platform (PLATFORM_ANDROID)
  50. * + Fixed issue with Android 1.6/2.2 (Thanks Tom Hirashima)
  51. *
  52. * 2010-04-27 (v1.8):
  53. * + Added iPad Support
  54. *
  55. * 2010-03-07 (v1.7):
  56. * + *MAJOR* Rebuild (preg_match and other "slow" routine removal(s))
  57. * + Almost allof Gary's original code has been replaced
  58. * + Large PHPUNIT testing environment created to validate new releases and additions
  59. * + Added FreeBSD Platform
  60. * + Added OpenBSD Platform
  61. * + Added NetBSD Platform
  62. * + Added SunOS Platform
  63. * + Added OpenSolaris Platform
  64. * + Added support of the Iceweazel Browser
  65. * + Added isChromeFrame() call to check if chromeframe is in use
  66. * + Moved the Opera check in front of the Firefox check due to legacy Opera User Agents
  67. * + Added the __toString() method (Thanks Deano)
  68. *
  69. * 2009-11-15:
  70. * + Updated the checkes for Firefox
  71. * + Added the NOKIA platform
  72. * + Added Checks for the NOKIA brower(s)
  73. *
  74. * 2009-11-08:
  75. * + PHP 5.3 Support
  76. * + Added support for BlackBerry OS and BlackBerry browser
  77. * + Added support for the Opera Mini browser
  78. * + Added additional documenation
  79. * + Added support for isRobot() and isMobile()
  80. * + Added support for Opera version 10
  81. * + Added support for deprecated Netscape Navigator version 9
  82. * + Added support for IceCat
  83. * + Added support for Shiretoko
  84. *
  85. * 2010-04-27 (v1.8):
  86. * + Added iPad Support
  87. *
  88. * 2009-08-18:
  89. * + Updated to support PHP 5.3 - removed all deprecated function calls
  90. * + Updated to remove all double quotes (") -- converted to single quotes (')
  91. *
  92. * 2009-04-27:
  93. * + Updated the IE check to remove a typo and bug (thanks John)
  94. *
  95. * 2009-04-22:
  96. * + Added detection for GoogleBot
  97. * + Added detection for the W3C Validator.
  98. * + Added detection for Yahoo! Slurp
  99. *
  100. * 2009-03-14:
  101. * + Added detection for iPods.
  102. * + Added Platform detection for iPhones
  103. * + Added Platform detection for iPods
  104. *
  105. * 2009-02-16: (Rick Hale)
  106. * + Added version detection for Android phones.
  107. *
  108. * 2008-12-09:
  109. * + Removed unused constant
  110. *
  111. * 2008-11-07:
  112. * + Added Google's Chrome to the detection list
  113. * + Added isBrowser(string) to the list of functions special thanks to
  114. * Daniel 'mavrick' Lang for the function concept (http://mavrick.id.au)
  115. *
  116. *
  117. * Gary White noted: "Since browser detection is so unreliable, I am
  118. * no longer maintaining this script. You are free to use and or
  119. * modify/update it as you want, however the author assumes no
  120. * responsibility for the accuracy of the detected values."
  121. *
  122. * Anyone experienced with Gary's script might be interested in these notes:
  123. *
  124. * Added class constants
  125. * Added detection and version detection for Google's Chrome
  126. * Updated the version detection for Amaya
  127. * Updated the version detection for Firefox
  128. * Updated the version detection for Lynx
  129. * Updated the version detection for WebTV
  130. * Updated the version detection for NetPositive
  131. * Updated the version detection for IE
  132. * Updated the version detection for OmniWeb
  133. * Updated the version detection for iCab
  134. * Updated the version detection for Safari
  135. * Updated Safari to remove mobile devices (iPhone)
  136. * Added detection for iPhone
  137. * Added detection for robots
  138. * Added detection for mobile devices
  139. * Added detection for BlackBerry
  140. * Removed Netscape checks (matches heavily with firefox & mozilla)
  141. *
  142. */
  143. class Browser {
  144. var $_agent = '';
  145. var $_browser_name = '';
  146. var $_version = '';
  147. var $_platform = '';
  148. var $_os = '';
  149. var $_is_aol = false;
  150. var $_is_mobile = false;
  151. var $_is_robot = false;
  152. var $_aol_version = '';
  153. var $BROWSER_UNKNOWN = 'unknown';
  154. var $VERSION_UNKNOWN = 'unknown';
  155. var $BROWSER_OPERA = 'Opera'; // http://www.opera.com/
  156. var $BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
  157. var $BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
  158. var $BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
  159. var $BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
  160. var $BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
  161. var $BROWSER_ICAB = 'iCab'; // http://www.icab.de/
  162. var $BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
  163. var $BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
  164. var $BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
  165. var $BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
  166. var $BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
  167. var $BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
  168. var $BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
  169. var $BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
  170. var $BROWSER_SAFARI = 'Safari'; // http://apple.com
  171. var $BROWSER_IPHONE = 'iPhone'; // http://apple.com
  172. var $BROWSER_IPOD = 'iPod'; // http://apple.com
  173. var $BROWSER_IPAD = 'iPad'; // http://apple.com
  174. var $BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
  175. var $BROWSER_ANDROID = 'Android'; // http://www.android.com/
  176. var $BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
  177. var $BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
  178. var $BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
  179. var $BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
  180. var $BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
  181. var $BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
  182. var $BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
  183. var $BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
  184. var $BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
  185. // http://en.wikipedia.org/wiki/Msnbot (used for Bing as well)
  186. var $BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
  187. var $BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
  188. var $BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
  189. var $BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
  190. var $PLATFORM_UNKNOWN = 'unknown';
  191. var $PLATFORM_WINDOWS = 'Windows';
  192. var $PLATFORM_WINDOWS_CE = 'Windows CE';
  193. var $PLATFORM_APPLE = 'Apple';
  194. var $PLATFORM_LINUX = 'Linux';
  195. var $PLATFORM_OS2 = 'OS/2';
  196. var $PLATFORM_BEOS = 'BeOS';
  197. var $PLATFORM_IPHONE = 'iPhone';
  198. var $PLATFORM_IPOD = 'iPod';
  199. var $PLATFORM_IPAD = 'iPad';
  200. var $PLATFORM_BLACKBERRY = 'BlackBerry';
  201. var $PLATFORM_NOKIA = 'Nokia';
  202. var $PLATFORM_FREEBSD = 'FreeBSD';
  203. var $PLATFORM_OPENBSD = 'OpenBSD';
  204. var $PLATFORM_NETBSD = 'NetBSD';
  205. var $PLATFORM_SUNOS = 'SunOS';
  206. var $PLATFORM_OPENSOLARIS = 'OpenSolaris';
  207. var $PLATFORM_ANDROID = 'Android';
  208. var $OPERATING_SYSTEM_UNKNOWN = 'unknown';
  209. function Browser($useragent="") {
  210. $this->reset();
  211. if( $useragent != "" ) {
  212. $this->setUserAgent($useragent);
  213. }
  214. else {
  215. $this->determine();
  216. }
  217. }
  218. /**
  219. * Reset all properties
  220. */
  221. function reset() {
  222. $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
  223. $this->_browser_name = $this->BROWSER_UNKNOWN;
  224. $this->_version = $this->VERSION_UNKNOWN;
  225. $this->_platform = $this->PLATFORM_UNKNOWN;
  226. $this->_os = $this->OPERATING_SYSTEM_UNKNOWN;
  227. $this->_is_aol = false;
  228. $this->_is_mobile = false;
  229. $this->_is_robot = false;
  230. $this->_aol_version = $this->VERSION_UNKNOWN;
  231. }
  232. /**
  233. * Check to see if the specific browser is valid
  234. * @param string $browserName
  235. * @return True if the browser is the specified browser
  236. */
  237. function isBrowser($browserName) { return( 0 == strcasecmp($this->_browser_name, trim($browserName))); }
  238. /**
  239. * The name of the browser. All return types are from the class contants
  240. * @return string Name of the browser
  241. */
  242. function getBrowser() { return $this->_browser_name; }
  243. /**
  244. * Set the name of the browser
  245. * @param $browser The name of the Browser
  246. */
  247. function setBrowser($browser) { return $this->_browser_name = $browser; }
  248. /**
  249. * The name of the platform. All return types are from the class contants
  250. * @return string Name of the browser
  251. */
  252. function getPlatform() { return $this->_platform; }
  253. /**
  254. * Set the name of the platform
  255. * @param $platform The name of the Platform
  256. */
  257. function setPlatform($platform) { return $this->_platform = $platform; }
  258. /**
  259. * The version of the browser.
  260. * @return string Version of the browser (will only contain alpha-numeric characters and a period)
  261. */
  262. function getVersion() { return $this->_version; }
  263. /**
  264. * Set the version of the browser
  265. * @param $version The version of the Browser
  266. */
  267. function setVersion($version) { $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/','',$version); }
  268. /**
  269. * The version of AOL.
  270. * @return string Version of AOL (will only contain alpha-numeric characters and a period)
  271. */
  272. function getAolVersion() { return $this->_aol_version; }
  273. /**
  274. * Set the version of AOL
  275. * @param $version The version of AOL
  276. */
  277. function setAolVersion($version) { $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/','',$version); }
  278. /**
  279. * Is the browser from AOL?
  280. * @return boolean True if the browser is from AOL otherwise false
  281. */
  282. function isAol() { return $this->_is_aol; }
  283. /**
  284. * Is the browser from a mobile device?
  285. * @return boolean True if the browser is from a mobile device otherwise false
  286. */
  287. function isMobile() { return $this->_is_mobile; }
  288. /**
  289. * Is the browser from a robot (ex Slurp,GoogleBot)?
  290. * @return boolean True if the browser is from a robot otherwise false
  291. */
  292. function isRobot() { return $this->_is_robot; }
  293. /**
  294. * Set the browser to be from AOL
  295. * @param $isAol
  296. */
  297. function setAol($isAol) { $this->_is_aol = $isAol; }
  298. /**
  299. * Set the Browser to be mobile
  300. * @param boolean $value is the browser a mobile brower or not
  301. */
  302. function setMobile($value=true) { $this->_is_mobile = $value; }
  303. /**
  304. * Set the Browser to be a robot
  305. * @param boolean $value is the browser a robot or not
  306. */
  307. function setRobot($value=true) { $this->_is_robot = $value; }
  308. /**
  309. * Get the user agent value in use to determine the browser
  310. * @return string The user agent from the HTTP header
  311. */
  312. function getUserAgent() { return $this->_agent; }
  313. /**
  314. * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
  315. * @param $agent_string The value for the User Agent
  316. */
  317. function setUserAgent($agent_string) {
  318. $this->reset();
  319. $this->_agent = $agent_string;
  320. $this->determine();
  321. }
  322. /**
  323. * Used to determine if the browser is actually "chromeframe"
  324. * @since 1.7
  325. * @return boolean True if the browser is using chromeframe
  326. */
  327. function isChromeFrame() {
  328. return( strpos($this->_agent,"chromeframe") !== false );
  329. }
  330. /**
  331. * Returns a formatted string with a summary of the details of the browser.
  332. * @return string formatted string with a summary of the browser
  333. */
  334. function __toString() {
  335. $text1 = $this->getUserAgent(); //grabs the UA (user agent) string
  336. $UAline1 = substr($text1, 0, 32); //the first line we print should only be the first 32 characters of the UA string
  337. $text2 = $this->getUserAgent();//now we grab it again and save it to a string
  338. $towrapUA = str_replace($UAline1, '', $text2);//the rest of the printoff (other than first line) is equivolent
  339. // to the whole string minus the part we printed off. IE
  340. // User Agent: thefirst32charactersfromUAline1
  341. // the rest of it is now stored in
  342. // $text2 to be printed off
  343. // but we need to add spaces before each line that is split other than line 1
  344. $space = '';
  345. for($i = 0; $i < 33; $i++) {
  346. $space .= ' ';
  347. }
  348. // now we split the remaining string of UA ($text2) into lines that are prefixed by spaces for formatting
  349. $wordwrapped = chunk_split($towrapUA, 32, "\n $space");
  350. return "Platform: {$this->getPlatform()} \n".
  351. " Browser Name: {$this->getBrowser()} \n" .
  352. " Browser Version: {$this->getVersion()} \n" .
  353. " User Agent String: $UAline1 \n " .
  354. "$wordwrapped ";
  355. }
  356. /**
  357. * Protected routine to calculate and determine what the browser is in use (including platform)
  358. */
  359. function determine() {
  360. $this->checkPlatform();
  361. $this->checkBrowsers();
  362. $this->checkForAol();
  363. }
  364. /**
  365. * Protected routine to determine the browser type
  366. * @return boolean True if the browser was detected otherwise false
  367. */
  368. function checkBrowsers() {
  369. return (
  370. // well-known, well-used
  371. // Special Notes:
  372. // (1) Opera must be checked before FireFox due to the odd
  373. // user agents used in some older versions of Opera
  374. // (2) WebTV is strapped onto Internet Explorer so we must
  375. // check for WebTV before IE
  376. // (3) (deprecated) Galeon is based on Firefox and needs to be
  377. // tested before Firefox is tested
  378. // (4) OmniWeb is based on Safari so OmniWeb check must occur
  379. // before Safari
  380. // (5) Netscape 9+ is based on Firefox so Netscape checks
  381. // before FireFox are necessary
  382. $this->checkBrowserWebTv() ||
  383. $this->checkBrowserInternetExplorer() ||
  384. $this->checkBrowserOpera() ||
  385. $this->checkBrowserGaleon() ||
  386. $this->checkBrowserNetscapeNavigator9Plus() ||
  387. $this->checkBrowserFirefox() ||
  388. $this->checkBrowserChrome() ||
  389. $this->checkBrowserOmniWeb() ||
  390. // common mobile
  391. $this->checkBrowserAndroid() ||
  392. $this->checkBrowseriPad() ||
  393. $this->checkBrowseriPod() ||
  394. $this->checkBrowseriPhone() ||
  395. $this->checkBrowserBlackBerry() ||
  396. $this->checkBrowserNokia() ||
  397. // common bots
  398. $this->checkBrowserGoogleBot() ||
  399. $this->checkBrowserMSNBot() ||
  400. $this->checkBrowserSlurp() ||
  401. // WebKit base check (post mobile and others)
  402. $this->checkBrowserSafari() ||
  403. // everyone else
  404. $this->checkBrowserNetPositive() ||
  405. $this->checkBrowserFirebird() ||
  406. $this->checkBrowserKonqueror() ||
  407. $this->checkBrowserIcab() ||
  408. $this->checkBrowserPhoenix() ||
  409. $this->checkBrowserAmaya() ||
  410. $this->checkBrowserLynx() ||
  411. $this->checkBrowserShiretoko() ||
  412. $this->checkBrowserIceCat() ||
  413. $this->checkBrowserW3CValidator() ||
  414. $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
  415. );
  416. }
  417. /**
  418. * Determine if the user is using a BlackBerry (last updated 1.7)
  419. * @return boolean True if the browser is the BlackBerry browser otherwise false
  420. */
  421. function checkBrowserBlackBerry() {
  422. if( stripos($this->_agent,'blackberry') !== false ) {
  423. $aresult = explode("/",stristr($this->_agent,"BlackBerry"));
  424. $aversion = explode(' ',$aresult[1]);
  425. $this->setVersion($aversion[0]);
  426. $this->_browser_name = $this->BROWSER_BLACKBERRY;
  427. $this->setMobile(true);
  428. return true;
  429. }
  430. return false;
  431. }
  432. /**
  433. * Determine if the user is using an AOL User Agent (last updated 1.7)
  434. * @return boolean True if the browser is from AOL otherwise false
  435. */
  436. function checkForAol() {
  437. $this->setAol(false);
  438. $this->setAolVersion($this->VERSION_UNKNOWN);
  439. if( stripos($this->_agent,'aol') !== false ) {
  440. $aversion = explode(' ',stristr($this->_agent, 'AOL'));
  441. $this->setAol(true);
  442. $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
  443. return true;
  444. }
  445. return false;
  446. }
  447. /**
  448. * Determine if the browser is the GoogleBot or not (last updated 1.7)
  449. * @return boolean True if the browser is the GoogletBot otherwise false
  450. */
  451. function checkBrowserGoogleBot() {
  452. if( stripos($this->_agent,'googlebot') !== false ) {
  453. $aresult = explode('/',stristr($this->_agent,'googlebot'));
  454. $aversion = explode(' ',$aresult[1]);
  455. $this->setVersion(str_replace(';','',$aversion[0]));
  456. $this->_browser_name = $this->BROWSER_GOOGLEBOT;
  457. $this->setRobot(true);
  458. return true;
  459. }
  460. return false;
  461. }
  462. /**
  463. * Determine if the browser is the MSNBot or not (last updated 1.9)
  464. * @return boolean True if the browser is the MSNBot otherwise false
  465. */
  466. function checkBrowserMSNBot() {
  467. if( stripos($this->_agent,"msnbot") !== false ) {
  468. $aresult = explode("/",stristr($this->_agent,"msnbot"));
  469. $aversion = explode(" ",$aresult[1]);
  470. $this->setVersion(str_replace(";","",$aversion[0]));
  471. $this->_browser_name = $this->BROWSER_MSNBOT;
  472. $this->setRobot(true);
  473. return true;
  474. }
  475. return false;
  476. }
  477. /**
  478. * Determine if the browser is the W3C Validator or not (last updated 1.7)
  479. * @return boolean True if the browser is the W3C Validator otherwise false
  480. */
  481. function checkBrowserW3CValidator() {
  482. if( stripos($this->_agent,'W3C-checklink') !== false ) {
  483. $aresult = explode('/',stristr($this->_agent,'W3C-checklink'));
  484. $aversion = explode(' ',$aresult[1]);
  485. $this->setVersion($aversion[0]);
  486. $this->_browser_name = $this->BROWSER_W3CVALIDATOR;
  487. return true;
  488. }
  489. else if( stripos($this->_agent,'W3C_Validator') !== false ) {
  490. // Some of the Validator versions do not delineate w/ a slash - add it back in
  491. $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
  492. $aresult = explode('/',stristr($ua,'W3C_Validator'));
  493. $aversion = explode(' ',$aresult[1]);
  494. $this->setVersion($aversion[0]);
  495. $this->_browser_name = $this->BROWSER_W3CVALIDATOR;
  496. return true;
  497. }
  498. return false;
  499. }
  500. /**
  501. * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
  502. * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
  503. */
  504. function checkBrowserSlurp() {
  505. if( stripos($this->_agent,'slurp') !== false ) {
  506. $aresult = explode('/',stristr($this->_agent,'Slurp'));
  507. $aversion = explode(' ',$aresult[1]);
  508. $this->setVersion($aversion[0]);
  509. $this->_browser_name = $this->BROWSER_SLURP;
  510. $this->setRobot(true);
  511. $this->setMobile(false);
  512. return true;
  513. }
  514. return false;
  515. }
  516. /**
  517. * Determine if the browser is Internet Explorer or not (last updated 1.7)
  518. * @return boolean True if the browser is Internet Explorer otherwise false
  519. */
  520. function checkBrowserInternetExplorer() {
  521. // Test for v1 - v1.5 IE
  522. if( stripos($this->_agent,'microsoft internet explorer') !== false ) {
  523. $this->setBrowser($this->BROWSER_IE);
  524. $this->setVersion('1.0');
  525. $aresult = stristr($this->_agent, '/');
  526. if( preg_match('/308|425|426|474|0b1/i', $aresult) ) {
  527. $this->setVersion('1.5');
  528. }
  529. return true;
  530. }
  531. // Test for versions > 1.5
  532. else if( stripos($this->_agent,'msie') !== false && stripos($this->_agent,'opera') === false ) {
  533. // See if the browser is the odd MSN Explorer
  534. if( stripos($this->_agent,'msnb') !== false ) {
  535. $aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'MSN'));
  536. $this->setBrowser( $this->BROWSER_MSN );
  537. $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
  538. return true;
  539. }
  540. $aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie'));
  541. $this->setBrowser( $this->BROWSER_IE );
  542. $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
  543. return true;
  544. }
  545. // Test for Pocket IE
  546. else if( stripos($this->_agent,'mspie') !== false || stripos($this->_agent,'pocket') !== false ) {
  547. $aresult = explode(' ',stristr($this->_agent,'mspie'));
  548. $this->setPlatform( $this->PLATFORM_WINDOWS_CE );
  549. $this->setBrowser( $this->BROWSER_POCKET_IE );
  550. $this->setMobile(true);
  551. if( stripos($this->_agent,'mspie') !== false ) {
  552. $this->setVersion($aresult[1]);
  553. }
  554. else {
  555. $aversion = explode('/',$this->_agent);
  556. $this->setVersion($aversion[1]);
  557. }
  558. return true;
  559. }
  560. return false;
  561. }
  562. /**
  563. * Determine if the browser is Opera or not (last updated 1.7)
  564. * @return boolean True if the browser is Opera otherwise false
  565. */
  566. function checkBrowserOpera() {
  567. if( stripos($this->_agent,'opera mini') !== false ) {
  568. $resultant = stristr($this->_agent, 'opera mini');
  569. if( preg_match('/\//',$resultant) ) {
  570. $aresult = explode('/',$resultant);
  571. $aversion = explode(' ',$aresult[1]);
  572. $this->setVersion($aversion[0]);
  573. }
  574. else {
  575. $aversion = explode(' ',stristr($resultant,'opera mini'));
  576. $this->setVersion($aversion[1]);
  577. }
  578. $this->_browser_name = $this->BROWSER_OPERA_MINI;
  579. $this->setMobile(true);
  580. return true;
  581. }
  582. else if( stripos($this->_agent,'opera') !== false ) {
  583. $resultant = stristr($this->_agent, 'opera');
  584. if( preg_match('/Version\/(10.*)$/',$resultant,$matches) ) {
  585. $this->setVersion($matches[1]);
  586. }
  587. else if( preg_match('/\//',$resultant) ) {
  588. $aresult = explode('/',str_replace("("," ",$resultant));
  589. $aversion = explode(' ',$aresult[1]);
  590. $this->setVersion($aversion[0]);
  591. }
  592. else {
  593. $aversion = explode(' ',stristr($resultant,'opera'));
  594. $this->setVersion(isset($aversion[1])?$aversion[1]:"");
  595. }
  596. $this->_browser_name = $this->BROWSER_OPERA;
  597. return true;
  598. }
  599. return false;
  600. }
  601. /**
  602. * Determine if the browser is Chrome or not (last updated 1.7)
  603. * @return boolean True if the browser is Chrome otherwise false
  604. */
  605. function checkBrowserChrome() {
  606. if( stripos($this->_agent,'Chrome') !== false ) {
  607. $aresult = explode('/',stristr($this->_agent,'Chrome'));
  608. $aversion = explode(' ',$aresult[1]);
  609. $this->setVersion($aversion[0]);
  610. $this->setBrowser($this->BROWSER_CHROME);
  611. return true;
  612. }
  613. return false;
  614. }
  615. /**
  616. * Determine if the browser is WebTv or not (last updated 1.7)
  617. * @return boolean True if the browser is WebTv otherwise false
  618. */
  619. function checkBrowserWebTv() {
  620. if( stripos($this->_agent,'webtv') !== false ) {
  621. $aresult = explode('/',stristr($this->_agent,'webtv'));
  622. $aversion = explode(' ',$aresult[1]);
  623. $this->setVersion($aversion[0]);
  624. $this->setBrowser($this->BROWSER_WEBTV);
  625. return true;
  626. }
  627. return false;
  628. }
  629. /**
  630. * Determine if the browser is NetPositive or not (last updated 1.7)
  631. * @return boolean True if the browser is NetPositive otherwise false
  632. */
  633. function checkBrowserNetPositive() {
  634. if( stripos($this->_agent,'NetPositive') !== false ) {
  635. $aresult = explode('/',stristr($this->_agent,'NetPositive'));
  636. $aversion = explode(' ',$aresult[1]);
  637. $this->setVersion(str_replace(array('(',')',';'),'',$aversion[0]));
  638. $this->setBrowser($this->BROWSER_NETPOSITIVE);
  639. return true;
  640. }
  641. return false;
  642. }
  643. /**
  644. * Determine if the browser is Galeon or not (last updated 1.7)
  645. * @return boolean True if the browser is Galeon otherwise false
  646. */
  647. function checkBrowserGaleon() {
  648. if( stripos($this->_agent,'galeon') !== false ) {
  649. $aresult = explode(' ',stristr($this->_agent,'galeon'));
  650. $aversion = explode('/',$aresult[0]);
  651. $this->setVersion($aversion[1]);
  652. $this->setBrowser($this->BROWSER_GALEON);
  653. return true;
  654. }
  655. return false;
  656. }
  657. /**
  658. * Determine if the browser is Konqueror or not (last updated 1.7)
  659. * @return boolean True if the browser is Konqueror otherwise false
  660. */
  661. function checkBrowserKonqueror() {
  662. if( stripos($this->_agent,'Konqueror') !== false ) {
  663. $aresult = explode(' ',stristr($this->_agent,'Konqueror'));
  664. $aversion = explode('/',$aresult[0]);
  665. $this->setVersion($aversion[1]);
  666. $this->setBrowser($this->BROWSER_KONQUEROR);
  667. return true;
  668. }
  669. return false;
  670. }
  671. /**
  672. * Determine if the browser is iCab or not (last updated 1.7)
  673. * @return boolean True if the browser is iCab otherwise false
  674. */
  675. function checkBrowserIcab() {
  676. if( stripos($this->_agent,'icab') !== false ) {
  677. $aversion = explode(' ',stristr(str_replace('/',' ',$this->_agent),'icab'));
  678. $this->setVersion($aversion[1]);
  679. $this->setBrowser($this->BROWSER_ICAB);
  680. return true;
  681. }
  682. return false;
  683. }
  684. /**
  685. * Determine if the browser is OmniWeb or not (last updated 1.7)
  686. * @return boolean True if the browser is OmniWeb otherwise false
  687. */
  688. function checkBrowserOmniWeb() {
  689. if( stripos($this->_agent,'omniweb') !== false ) {
  690. $aresult = explode('/',stristr($this->_agent,'omniweb'));
  691. $aversion = explode(' ',isset($aresult[1])?$aresult[1]:"");
  692. $this->setVersion($aversion[0]);
  693. $this->setBrowser($this->BROWSER_OMNIWEB);
  694. return true;
  695. }
  696. return false;
  697. }
  698. /**
  699. * Determine if the browser is Phoenix or not (last updated 1.7)
  700. * @return boolean True if the browser is Phoenix otherwise false
  701. */
  702. function checkBrowserPhoenix() {
  703. if( stripos($this->_agent,'Phoenix') !== false ) {
  704. $aversion = explode('/',stristr($this->_agent,'Phoenix'));
  705. $this->setVersion($aversion[1]);
  706. $this->setBrowser($this->BROWSER_PHOENIX);
  707. return true;
  708. }
  709. return false;
  710. }
  711. /**
  712. * Determine if the browser is Firebird or not (last updated 1.7)
  713. * @return boolean True if the browser is Firebird otherwise false
  714. */
  715. function checkBrowserFirebird() {
  716. if( stripos($this->_agent,'Firebird') !== false ) {
  717. $aversion = explode('/',stristr($this->_agent,'Firebird'));
  718. $this->setVersion($aversion[1]);
  719. $this->setBrowser($this->BROWSER_FIREBIRD);
  720. return true;
  721. }
  722. return false;
  723. }
  724. /**
  725. * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
  726. * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
  727. * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
  728. */
  729. function checkBrowserNetscapeNavigator9Plus() {
  730. if( stripos($this->_agent,'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i',$this->_agent,$matches) ) {
  731. $this->setVersion($matches[1]);
  732. $this->setBrowser($this->BROWSER_NETSCAPE_NAVIGATOR);
  733. return true;
  734. }
  735. else if( stripos($this->_agent,'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i',$this->_agent,$matches) ) {
  736. $this->setVersion($matches[1]);
  737. $this->setBrowser($this->BROWSER_NETSCAPE_NAVIGATOR);
  738. return true;
  739. }
  740. return false;
  741. }
  742. /**
  743. * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
  744. * @return boolean True if the browser is Shiretoko otherwise false
  745. */
  746. function checkBrowserShiretoko() {
  747. if( stripos($this->_agent,'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i',$this->_agent,$matches) ) {
  748. $this->setVersion($matches[1]);
  749. $this->setBrowser($this->BROWSER_SHIRETOKO);
  750. return true;
  751. }
  752. return false;
  753. }
  754. /**
  755. * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
  756. * @return boolean True if the browser is Ice Cat otherwise false
  757. */
  758. function checkBrowserIceCat() {
  759. if( stripos($this->_agent,'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i',$this->_agent,$matches) ) {
  760. $this->setVersion($matches[1]);
  761. $this->setBrowser($this->BROWSER_ICECAT);
  762. return true;
  763. }
  764. return false;
  765. }
  766. /**
  767. * Determine if the browser is Nokia or not (last updated 1.7)
  768. * @return boolean True if the browser is Nokia otherwise false
  769. */
  770. function checkBrowserNokia() {
  771. if( preg_match("/Nokia([^\/]+)\/([^ SP]+)/i",$this->_agent,$matches) ) {
  772. $this->setVersion($matches[2]);
  773. if( stripos($this->_agent,'Series60') !== false || strpos($this->_agent,'S60') !== false ) {
  774. $this->setBrowser($this->BROWSER_NOKIA_S60);
  775. }
  776. else {
  777. $this->setBrowser( $this->BROWSER_NOKIA );
  778. }
  779. $this->setMobile(true);
  780. return true;
  781. }
  782. return false;
  783. }
  784. /**
  785. * Determine if the browser is Firefox or not (last updated 1.7)
  786. * @return boolean True if the browser is Firefox otherwise false
  787. */
  788. function checkBrowserFirefox() {
  789. if( stripos($this->_agent,'safari') === false ) {
  790. if( preg_match("/Firefox[\/ \(]([^ ;\)]+)/i",$this->_agent,$matches) ) {
  791. $this->setVersion($matches[1]);
  792. $this->setBrowser($this->BROWSER_FIREFOX);
  793. return true;
  794. }
  795. else if( preg_match("/Firefox$/i",$this->_agent,$matches) ) {
  796. $this->setVersion("");
  797. $this->setBrowser($this->BROWSER_FIREFOX);
  798. return true;
  799. }
  800. }
  801. return false;
  802. }
  803. /**
  804. * Determine if the browser is Firefox or not (last updated 1.7)
  805. * @return boolean True if the browser is Firefox otherwise false
  806. */
  807. function checkBrowserIceweasel() {
  808. if( stripos($this->_agent,'Iceweasel') !== false ) {
  809. $aresult = explode('/',stristr($this->_agent,'Iceweasel'));
  810. $aversion = explode(' ',$aresult[1]);
  811. $this->setVersion($aversion[0]);
  812. $this->setBrowser($this->BROWSER_ICEWEASEL);
  813. return true;
  814. }
  815. return false;
  816. }
  817. /**
  818. * Determine if the browser is Mozilla or not (last updated 1.7)
  819. * @return boolean True if the browser is Mozilla otherwise false
  820. */
  821. function checkBrowserMozilla() {
  822. if( stripos($this->_agent,'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent) && stripos($this->_agent,'netscape') === false) {
  823. $aversion = explode(' ',stristr($this->_agent,'rv:'));
  824. preg_match('/rv:[0-9].[0-9][a-b]?/i',$this->_agent,$aversion);
  825. $this->setVersion(str_replace('rv:','',$aversion[0]));
  826. $this->setBrowser($this->BROWSER_MOZILLA);
  827. return true;
  828. }
  829. else if( stripos($this->_agent,'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i',$this->_agent) && stripos($this->_agent,'netscape') === false ) {
  830. $aversion = explode('',stristr($this->_agent,'rv:'));
  831. $this->setVersion(str_replace('rv:','',$aversion[0]));
  832. $this->setBrowser($this->BROWSER_MOZILLA);
  833. return true;
  834. }
  835. else if( stripos($this->_agent,'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i',$this->_agent,$matches) && stripos($this->_agent,'netscape') === false ) {
  836. $this->setVersion($matches[1]);
  837. $this->setBrowser($this->BROWSER_MOZILLA);
  838. return true;
  839. }
  840. return false;
  841. }
  842. /**
  843. * Determine if the browser is Lynx or not (last updated 1.7)
  844. * @return boolean True if the browser is Lynx otherwise false
  845. */
  846. function checkBrowserLynx() {
  847. if( stripos($this->_agent,'lynx') !== false ) {
  848. $aresult = explode('/',stristr($this->_agent,'Lynx'));
  849. $aversion = explode(' ',(isset($aresult[1])?$aresult[1]:""));
  850. $this->setVersion($aversion[0]);
  851. $this->setBrowser($this->BROWSER_LYNX);
  852. return true;
  853. }
  854. return false;
  855. }
  856. /**
  857. * Determine if the browser is Amaya or not (last updated 1.7)
  858. * @return boolean True if the browser is Amaya otherwise false
  859. */
  860. function checkBrowserAmaya() {
  861. if( stripos($this->_agent,'amaya') !== false ) {
  862. $aresult = explode('/',stristr($this->_agent,'Amaya'));
  863. $aversion = explode(' ',$aresult[1]);
  864. $this->setVersion($aversion[0]);
  865. $this->setBrowser($this->BROWSER_AMAYA);
  866. return true;
  867. }
  868. return false;
  869. }
  870. /**
  871. * Determine if the browser is Safari or not (last updated 1.7)
  872. * @return boolean True if the browser is Safari otherwise false
  873. */
  874. function checkBrowserSafari() {
  875. if( stripos($this->_agent,'Safari') !== false && stripos($this->_agent,'iPhone') === false && stripos($this->_agent,'iPod') === false ) {
  876. $aresult = explode('/',stristr($this->_agent,'Version'));
  877. if( isset($aresult[1]) ) {
  878. $aversion = explode(' ',$aresult[1]);
  879. $this->setVersion($aversion[0]);
  880. }
  881. else {
  882. $this->setVersion($this->VERSION_UNKNOWN);
  883. }
  884. $this->setBrowser($this->BROWSER_SAFARI);
  885. return true;
  886. }
  887. return false;
  888. }
  889. /**
  890. * Determine if the browser is iPhone or not (last updated 1.7)
  891. * @return boolean True if the browser is iPhone otherwise false
  892. */
  893. function checkBrowseriPhone() {
  894. if( stripos($this->_agent,'iPhone') !== false ) {
  895. $aresult = explode('/',stristr($this->_agent,'Version'));
  896. if( isset($aresult[1]) ) {
  897. $aversion = explode(' ',$aresult[1]);
  898. $this->setVersion($aversion[0]);
  899. }
  900. else {
  901. $this->setVersion($this->VERSION_UNKNOWN);
  902. }
  903. $this->setMobile(true);
  904. $this->setBrowser($this->BROWSER_IPHONE);
  905. return true;
  906. }
  907. return false;
  908. }
  909. /**
  910. * Determine if the browser is iPod or not (last updated 1.7)
  911. * @return boolean True if the browser is iPod otherwise false
  912. */
  913. function checkBrowseriPad() {
  914. if( stripos($this->_agent,'iPad') !== false ) {
  915. $aresult = explode('/',stristr($this->_agent,'Version'));
  916. if( isset($aresult[1]) ) {
  917. $aversion = explode(' ',$aresult[1]);
  918. $this->setVersion($aversion[0]);
  919. }
  920. else {
  921. $this->setVersion($this->VERSION_UNKNOWN);
  922. }
  923. $this->setMobile(true);
  924. $this->setBrowser($this->BROWSER_IPAD);
  925. return true;
  926. }
  927. return false;
  928. }
  929. /**
  930. * Determine if the browser is iPod or not (last updated 1.7)
  931. * @return boolean True if the browser is iPod otherwise false
  932. */
  933. function checkBrowseriPod() {
  934. if( stripos($this->_agent,'iPod') !== false ) {
  935. $aresult = explode('/',stristr($this->_agent,'Version'));
  936. if( isset($aresult[1]) ) {
  937. $aversion = explode(' ',$aresult[1]);
  938. $this->setVersion($aversion[0]);
  939. }
  940. else {
  941. $this->setVersion($this->VERSION_UNKNOWN);
  942. }
  943. $this->setMobile(true);
  944. $this->setBrowser($this->BROWSER_IPOD);
  945. return true;
  946. }
  947. return false;
  948. }
  949. /**
  950. * Determine if the browser is Android or not (last updated 1.7)
  951. * @return boolean True if the browser is Android otherwise false
  952. */
  953. function checkBrowserAndroid() {
  954. if( stripos($this->_agent,'Android') !== false ) {
  955. $aresult = explode(' ',stristr($this->_agent,'Android'));
  956. if( isset($aresult[1]) ) {
  957. $aversion = explode(' ',$aresult[1]);
  958. $this->setVersion($aversion[0]);
  959. }
  960. else {
  961. $this->setVersion($this->VERSION_UNKNOWN);
  962. }
  963. $this->setMobile(true);
  964. $this->setBrowser($this->BROWSER_ANDROID);
  965. return true;
  966. }
  967. return false;
  968. }
  969. /**
  970. * Determine the user's platform (last updated 1.7)
  971. */
  972. function checkPlatform() {
  973. if( stripos($this->_agent, 'windows') !== false ) {
  974. $this->_platform = $this->PLATFORM_WINDOWS;
  975. }
  976. else if( stripos($this->_agent, 'iPad') !== false ) {
  977. $this->_platform = $this->PLATFORM_IPAD;
  978. }
  979. else if( stripos($this->_agent, 'iPod') !== false ) {
  980. $this->_platform = $this->PLATFORM_IPOD;
  981. }
  982. else if( stripos($this->_agent, 'iPhone') !== false ) {
  983. $this->_platform = $this->PLATFORM_IPHONE;
  984. }
  985. elseif( stripos($this->_agent, 'mac') !== false ) {
  986. $this->_platform = $this->PLATFORM_APPLE;
  987. }
  988. elseif( stripos($this->_agent, 'android') !== false ) {
  989. $this->_platform = $this->PLATFORM_ANDROID;
  990. }
  991. elseif( stripos($this->_agent, 'linux') !== false ) {
  992. $this->_platform = $this->PLATFORM_LINUX;
  993. }
  994. else if( stripos($this->_agent, 'Nokia') !== false ) {
  995. $this->_platform = $this->PLATFORM_NOKIA;
  996. }
  997. else if( stripos($this->_agent, 'BlackBerry') !== false ) {
  998. $this->_platform = $this->PLATFORM_BLACKBERRY;
  999. }
  1000. elseif( stripos($this->_agent,'FreeBSD') !== false ) {
  1001. $this->_platform = $this->PLATFORM_FREEBSD;
  1002. }
  1003. elseif( stripos($this->_agent,'OpenBSD') !== false ) {
  1004. $this->_platform = $this->PLATFORM_OPENBSD;
  1005. }
  1006. elseif( stripos($this->_agent,'NetBSD') !== false ) {
  1007. $this->_platform = $this->PLATFORM_NETBSD;
  1008. }
  1009. elseif( stripos($this->_agent, 'OpenSolaris') !== false ) {
  1010. $this->_platform = $this->PLATFORM_OPENSOLARIS;
  1011. }
  1012. elseif( stripos($this->_agent, 'SunOS') !== false ) {
  1013. $this->_platform = $this->PLATFORM_SUNOS;
  1014. }
  1015. elseif( stripos($this->_agent, 'OS\/2') !== false ) {
  1016. $this->_platform = $this->PLATFORM_OS2;
  1017. }
  1018. elseif( stripos($this->_agent, 'BeOS') !== false ) {
  1019. $this->_platform = $this->PLATFORM_BEOS;
  1020. }
  1021. elseif( stripos($this->_agent, 'win') !== false ) {
  1022. $this->_platform = $this->PLATFORM_WINDOWS;
  1023. }
  1024. }
  1025. }
  1026. ?>