\Browser
Typical Usage:
$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
echo 'You have FireFox version 2 or greater';
}
User Agents Sampled from: http://www.useragentstring.com/
This implementation is based on the original work from Gary White
http://apptools.com/phptools/browser/
Synopsis
class Browser
{
- // constants
- const BROWSER_UNKNOWN = 'unknown';
- const VERSION_UNKNOWN = 'unknown';
- const BROWSER_OPERA = 'Opera';
- const BROWSER_OPERA_MINI = 'Opera Mini';
- const BROWSER_WEBTV = 'WebTV';
- const BROWSER_EDGE = 'Edge';
- const BROWSER_IE = 'Internet Explorer';
- const BROWSER_POCKET_IE = 'Pocket Internet Explorer';
- const BROWSER_KONQUEROR = 'Konqueror';
- const BROWSER_ICAB = 'iCab';
- const BROWSER_OMNIWEB = 'OmniWeb';
- const BROWSER_FIREBIRD = 'Firebird';
- const BROWSER_FIREFOX = 'Firefox';
- const BROWSER_ICEWEASEL = 'Iceweasel';
- const BROWSER_SHIRETOKO = 'Shiretoko';
- const BROWSER_MOZILLA = 'Mozilla';
- const BROWSER_AMAYA = 'Amaya';
- const BROWSER_LYNX = 'Lynx';
- const BROWSER_SAFARI = 'Safari';
- const BROWSER_IPHONE = 'iPhone';
- const BROWSER_IPOD = 'iPod';
- const BROWSER_IPAD = 'iPad';
- const BROWSER_CHROME = 'Chrome';
- const BROWSER_ANDROID = 'Android';
- const BROWSER_GOOGLEBOT = 'GoogleBot';
- const BROWSER_YANDEXBOT = 'YandexBot';
- const BROWSER_YANDEXIMAGERESIZER_BOT = 'YandexImageResizer';
- const BROWSER_YANDEXIMAGES_BOT = 'YandexImages';
- const BROWSER_YANDEXVIDEO_BOT = 'YandexVideo';
- const BROWSER_YANDEXMEDIA_BOT = 'YandexMedia';
- const BROWSER_YANDEXBLOGS_BOT = 'YandexBlogs';
- const BROWSER_YANDEXFAVICONS_BOT = 'YandexFavicons';
- const BROWSER_YANDEXWEBMASTER_BOT = 'YandexWebmaster';
- const BROWSER_YANDEXDIRECT_BOT = 'YandexDirect';
- const BROWSER_YANDEXMETRIKA_BOT = 'YandexMetrika';
- const BROWSER_YANDEXNEWS_BOT = 'YandexNews';
- const BROWSER_YANDEXCATALOG_BOT = 'YandexCatalog';
- const BROWSER_SLURP = 'Yahoo! Slurp';
- const BROWSER_W3CVALIDATOR = 'W3C Validator';
- const BROWSER_BLACKBERRY = 'BlackBerry';
- const BROWSER_ICECAT = 'IceCat';
- const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser';
- const BROWSER_NOKIA = 'Nokia Browser';
- const BROWSER_MSN = 'MSN Browser';
- const BROWSER_MSNBOT = 'MSN Bot';
- const BROWSER_BINGBOT = 'Bing Bot';
- const BROWSER_VIVALDI = 'Vivalidi';
- const BROWSER_YANDEX = 'Yandex';
- const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator';
- const BROWSER_GALEON = 'Galeon';
- const BROWSER_NETPOSITIVE = 'NetPositive';
- const BROWSER_PHOENIX = 'Phoenix';
- const BROWSER_PLAYSTATION = "PlayStation";
- const BROWSER_SAMSUNG = "SamsungBrowser";
- const BROWSER_SILK = "Silk";
- const BROWSER_I_FRAME = "Iframely";
- const BROWSER_COCOA = "CocoaRestClient";
- const PLATFORM_UNKNOWN = 'unknown';
- const PLATFORM_WINDOWS = 'Windows';
- const PLATFORM_WINDOWS_CE = 'Windows CE';
- const PLATFORM_APPLE = 'Apple';
- const PLATFORM_LINUX = 'Linux';
- const PLATFORM_OS2 = 'OS/2';
- const PLATFORM_BEOS = 'BeOS';
- const PLATFORM_IPHONE = 'iPhone';
- const PLATFORM_IPOD = 'iPod';
- const PLATFORM_IPAD = 'iPad';
- const PLATFORM_BLACKBERRY = 'BlackBerry';
- const PLATFORM_NOKIA = 'Nokia';
- const PLATFORM_FREEBSD = 'FreeBSD';
- const PLATFORM_OPENBSD = 'OpenBSD';
- const PLATFORM_NETBSD = 'NetBSD';
- const PLATFORM_SUNOS = 'SunOS';
- const PLATFORM_OPENSOLARIS = 'OpenSolaris';
- const PLATFORM_ANDROID = 'Android';
- const PLATFORM_PLAYSTATION = "Sony PlayStation";
- const PLATFORM_ROKU = "Roku";
- const PLATFORM_APPLE_TV = "Apple TV";
- const PLATFORM_TERMINAL = "Terminal";
- const PLATFORM_FIRE_OS = "Fire OS";
- const PLATFORM_SMART_TV = "SMART-TV";
- const PLATFORM_CHROME_OS = "Chrome OS";
- const PLATFORM_JAVA_ANDROID = "Java/Android";
- const PLATFORM_POSTMAN = "Postman";
- const PLATFORM_I_FRAME = "Iframely";
- const OPERATING_SYSTEM_UNKNOWN = 'unknown';
- // members
- private string $_agent = '';
- private string $_browser_name = '';
- private string $_version = '';
- private string $_platform = '';
- private string $_os = '';
- private boolean $_is_aol = false;
- private boolean $_is_mobile = false;
- private boolean $_is_tablet = false;
- private boolean $_is_robot = false;
- private boolean $_is_facebook = false;
- private string $_aol_version = '';
- // methods
- public void __construct()
- public void reset()
- public bool isBrowser()
- public string getBrowser()
- public void setBrowser()
- public string getPlatform()
- public void setPlatform()
- public string getVersion()
- public void setVersion()
- public string getAolVersion()
- public void setAolVersion()
- public boolean isAol()
- public boolean isMobile()
- public boolean isTablet()
- public boolean isRobot()
- public boolean isFacebook()
- public void setAol()
- protected void setMobile()
- protected void setTablet()
- protected void setRobot()
- protected void setFacebook()
- public string getUserAgent()
- public void setUserAgent()
- public boolean isChromeFrame()
- public string __toString()
- protected void determine()
- protected boolean checkBrowsers()
- protected boolean checkBrowserBlackBerry()
- protected boolean checkForAol()
- protected boolean checkBrowserGoogleBot()
- protected boolean checkBrowserYandexBot()
- protected boolean checkBrowserYandexImageResizerBot()
- protected boolean checkBrowserYandexCatalogBot()
- protected boolean checkBrowserYandexNewsBot()
- protected boolean checkBrowserYandexMetrikaBot()
- protected boolean checkBrowserYandexDirectBot()
- protected boolean checkBrowserYandexWebmasterBot()
- protected boolean checkBrowserYandexFaviconsBot()
- protected boolean checkBrowserYandexBlogsBot()
- protected boolean checkBrowserYandexMediaBot()
- protected boolean checkBrowserYandexVideoBot()
- protected boolean checkBrowserYandexImagesBot()
- protected boolean checkBrowserMSNBot()
- protected boolean checkBrowserBingBot()
- protected boolean checkBrowserW3CValidator()
- protected boolean checkBrowserSlurp()
- protected boolean checkBrowserEdge()
- protected boolean checkBrowserInternetExplorer()
- protected boolean checkBrowserOpera()
- protected boolean checkBrowserChrome()
- protected boolean checkBrowserWebTv()
- protected boolean checkBrowserNetPositive()
- protected boolean checkBrowserGaleon()
- protected boolean checkBrowserKonqueror()
- protected boolean checkBrowserIcab()
- protected boolean checkBrowserOmniWeb()
- protected boolean checkBrowserPhoenix()
- protected boolean checkBrowserFirebird()
- protected boolean checkBrowserNetscapeNavigator9Plus()
- protected boolean checkBrowserShiretoko()
- protected boolean checkBrowserIceCat()
- protected boolean checkBrowserNokia()
- protected boolean checkBrowserFirefox()
- protected boolean checkBrowserIceweasel()
- protected boolean checkBrowserMozilla()
- protected boolean checkBrowserLynx()
- protected boolean checkBrowserAmaya()
- protected boolean checkBrowserSafari()
- protected void checkBrowserSamsung()
- protected void checkBrowserSilk()
- protected void checkBrowserIframely()
- protected void checkBrowserCocoa()
- protected boolean checkFacebookExternalHit()
- protected boolean checkForFacebookIos()
- protected boolean getSafariVersionOnIos()
- protected boolean getChromeVersionOnIos()
- protected boolean checkBrowseriPhone()
- protected boolean checkBrowseriPad()
- protected boolean checkBrowseriPod()
- protected boolean checkBrowserAndroid()
- protected boolean checkBrowserVivaldi()
- protected boolean checkBrowserYandex()
- protected boolean checkBrowserPlayStation()
- protected void checkPlatform()
Constants
Name | Value |
---|---|
BROWSER_UNKNOWN | 'unknown' |
VERSION_UNKNOWN | 'unknown' |
BROWSER_OPERA | 'Opera' |
BROWSER_OPERA_MINI | 'Opera Mini' |
BROWSER_WEBTV | 'WebTV' |
BROWSER_EDGE | 'Edge' |
BROWSER_IE | 'Internet Explorer' |
BROWSER_POCKET_IE | 'Pocket Internet Explorer' |
BROWSER_KONQUEROR | 'Konqueror' |
BROWSER_ICAB | 'iCab' |
BROWSER_OMNIWEB | 'OmniWeb' |
BROWSER_FIREBIRD | 'Firebird' |
BROWSER_FIREFOX | 'Firefox' |
BROWSER_ICEWEASEL | 'Iceweasel' |
BROWSER_SHIRETOKO | 'Shiretoko' |
BROWSER_MOZILLA | 'Mozilla' |
BROWSER_AMAYA | 'Amaya' |
BROWSER_LYNX | 'Lynx' |
BROWSER_SAFARI | 'Safari' |
BROWSER_IPHONE | 'iPhone' |
BROWSER_IPOD | 'iPod' |
BROWSER_IPAD | 'iPad' |
BROWSER_CHROME | 'Chrome' |
BROWSER_ANDROID | 'Android' |
BROWSER_GOOGLEBOT | 'GoogleBot' |
BROWSER_YANDEXBOT | 'YandexBot' |
BROWSER_YANDEXIMAGERESIZER_BOT | 'YandexImageResizer' |
BROWSER_YANDEXIMAGES_BOT | 'YandexImages' |
BROWSER_YANDEXVIDEO_BOT | 'YandexVideo' |
BROWSER_YANDEXMEDIA_BOT | 'YandexMedia' |
BROWSER_YANDEXBLOGS_BOT | 'YandexBlogs' |
BROWSER_YANDEXFAVICONS_BOT | 'YandexFavicons' |
BROWSER_YANDEXWEBMASTER_BOT | 'YandexWebmaster' |
BROWSER_YANDEXDIRECT_BOT | 'YandexDirect' |
BROWSER_YANDEXMETRIKA_BOT | 'YandexMetrika' |
BROWSER_YANDEXNEWS_BOT | 'YandexNews' |
BROWSER_YANDEXCATALOG_BOT | 'YandexCatalog' |
BROWSER_SLURP | 'Yahoo! Slurp' |
BROWSER_W3CVALIDATOR | 'W3C Validator' |
BROWSER_BLACKBERRY | 'BlackBerry' |
BROWSER_ICECAT | 'IceCat' |
BROWSER_NOKIA_S60 | 'Nokia S60 OSS Browser' |
BROWSER_NOKIA | 'Nokia Browser' |
BROWSER_MSN | 'MSN Browser' |
BROWSER_MSNBOT | 'MSN Bot' |
BROWSER_BINGBOT | 'Bing Bot' |
BROWSER_VIVALDI | 'Vivalidi' |
BROWSER_YANDEX | 'Yandex' |
BROWSER_NETSCAPE_NAVIGATOR | 'Netscape Navigator' |
BROWSER_GALEON | 'Galeon' |
BROWSER_NETPOSITIVE | 'NetPositive' |
BROWSER_PHOENIX | 'Phoenix' |
BROWSER_PLAYSTATION | "PlayStation" |
BROWSER_SAMSUNG | "SamsungBrowser" |
BROWSER_SILK | "Silk" |
BROWSER_I_FRAME | "Iframely" |
BROWSER_COCOA | "CocoaRestClient" |
PLATFORM_UNKNOWN | 'unknown' |
PLATFORM_WINDOWS | 'Windows' |
PLATFORM_WINDOWS_CE | 'Windows CE' |
PLATFORM_APPLE | 'Apple' |
PLATFORM_LINUX | 'Linux' |
PLATFORM_OS2 | 'OS/2' |
PLATFORM_BEOS | 'BeOS' |
PLATFORM_IPHONE | 'iPhone' |
PLATFORM_IPOD | 'iPod' |
PLATFORM_IPAD | 'iPad' |
PLATFORM_BLACKBERRY | 'BlackBerry' |
PLATFORM_NOKIA | 'Nokia' |
PLATFORM_FREEBSD | 'FreeBSD' |
PLATFORM_OPENBSD | 'OpenBSD' |
PLATFORM_NETBSD | 'NetBSD' |
PLATFORM_SUNOS | 'SunOS' |
PLATFORM_OPENSOLARIS | 'OpenSolaris' |
PLATFORM_ANDROID | 'Android' |
PLATFORM_PLAYSTATION | "Sony PlayStation" |
PLATFORM_ROKU | "Roku" |
PLATFORM_APPLE_TV | "Apple TV" |
PLATFORM_TERMINAL | "Terminal" |
PLATFORM_FIRE_OS | "Fire OS" |
PLATFORM_SMART_TV | "SMART-TV" |
PLATFORM_CHROME_OS | "Chrome OS" |
PLATFORM_JAVA_ANDROID | "Java/Android" |
PLATFORM_POSTMAN | "Postman" |
PLATFORM_I_FRAME | "Iframely" |
OPERATING_SYSTEM_UNKNOWN | 'unknown' |
Members
private
- $_agent
- $_aol_version
- $_browser_name
- $_is_aol
- $_is_facebook
- $_is_mobile
- $_is_robot
- $_is_tablet
- $_os
- $_platform
- $_version
Methods
protected
- checkBrowserAmaya() — Determine if the browser is Amaya or not (last updated 1.7)
- checkBrowserAndroid() — Determine if the browser is Android or not (last updated 1.7)
- checkBrowserBingBot() — Determine if the browser is the BingBot or not (last updated 1.9)
- checkBrowserBlackBerry() — Determine if the user is using a BlackBerry (last updated 1.7)
- checkBrowserChrome() — Determine if the browser is Chrome or not (last updated 1.7)
- checkBrowserCocoa()
- checkBrowserEdge() — Determine if the browser is Edge or not
- checkBrowserFirebird() — Determine if the browser is Firebird or not (last updated 1.7)
- checkBrowserFirefox() — Determine if the browser is Firefox or not (last updated 1.7)
- checkBrowserGaleon() — Determine if the browser is Galeon or not (last updated 1.7)
- checkBrowserGoogleBot() — Determine if the browser is the GoogleBot or not (last updated 1.7)
- checkBrowserIcab() — Determine if the browser is iCab or not (last updated 1.7)
- checkBrowserIceCat() — Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
- checkBrowserIceweasel() — Determine if the browser is Firefox or not (last updated 1.7)
- checkBrowserIframely()
- checkBrowserInternetExplorer() — Determine if the browser is Internet Explorer or not (last updated 1.7)
- checkBrowserKonqueror() — Determine if the browser is Konqueror or not (last updated 1.7)
- checkBrowserLynx() — Determine if the browser is Lynx or not (last updated 1.7)
- checkBrowserMSNBot() — Determine if the browser is the MSNBot or not (last updated 1.9)
- checkBrowserMozilla() — Determine if the browser is Mozilla or not (last updated 1.7)
- checkBrowserNetPositive() — Determine if the browser is NetPositive or not (last updated 1.7)
- checkBrowserNokia() — Determine if the browser is Nokia or not (last updated 1.7)
- checkBrowserOmniWeb() — Determine if the browser is OmniWeb or not (last updated 1.7)
- checkBrowserOpera() — Determine if the browser is Opera or not (last updated 1.7)
- checkBrowserPhoenix() — Determine if the browser is Phoenix or not (last updated 1.7)
- checkBrowserPlayStation() — Determine if the browser is a PlayStation
- checkBrowserSafari() — Determine if the browser is Safari or not (last updated 1.7)
- checkBrowserSamsung()
- checkBrowserShiretoko() — Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
- checkBrowserSilk()
- checkBrowserSlurp() — Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
- checkBrowserVivaldi() — Determine if the browser is Vivaldi
- checkBrowserW3CValidator() — Determine if the browser is the W3C Validator or not (last updated 1.7)
- checkBrowserWebTv() — Determine if the browser is WebTv or not (last updated 1.7)
- checkBrowserYandex() — Determine if the browser is Yandex
- checkBrowserYandexBlogsBot() — Determine if the browser is the YandexBlogs or not
- checkBrowserYandexBot() — Determine if the browser is the YandexBot or not
- checkBrowserYandexCatalogBot() — Determine if the browser is the YandexCatalog or not
- checkBrowserYandexDirectBot() — Determine if the browser is the YandexDirect or not
- checkBrowserYandexFaviconsBot() — Determine if the browser is the YandexFavicons or not
- checkBrowserYandexImageResizerBot() — Determine if the browser is the YandexImageResizer or not
- checkBrowserYandexImagesBot() — Determine if the browser is the YandexImages or not
- checkBrowserYandexMediaBot() — Determine if the browser is the YandexMedia or not
- checkBrowserYandexMetrikaBot() — Determine if the browser is the YandexMetrika or not
- checkBrowserYandexNewsBot() — Determine if the browser is the YandexNews or not
- checkBrowserYandexVideoBot() — Determine if the browser is the YandexVideo or not
- checkBrowserYandexWebmasterBot() — Determine if the browser is the YandexWebmaster or not
- checkBrowseriPad() — Determine if the browser is iPad or not (last updated 1.7)
- checkBrowseriPhone() — Determine if the browser is iPhone or not (last updated 1.7)
- checkBrowseriPod() — Determine if the browser is iPod or not (last updated 1.7)
- checkBrowsers() — Protected routine to determine the browser type
- checkFacebookExternalHit() — Detect if URL is loaded from FacebookExternalHit
- checkForAol() — Determine if the user is using an AOL User Agent (last updated 1.7)
- checkForFacebookIos() — Detect if URL is being loaded from internal Facebook browser
- checkPlatform() — Determine the user's platform (last updated 2.0)
- determine() — Protected routine to calculate and determine what the browser is in use (including platform)
- getChromeVersionOnIos() — Detect Version for the Chrome browser on iOS devices
- getSafariVersionOnIos() — Detect Version for the Safari browser on iOS devices
- setFacebook() — Set the Browser to be a Facebook request
- setMobile() — Set the Browser to be mobile
- setRobot() — Set the Browser to be a robot
- setTablet() — Set the Browser to be tablet
public
- __construct() — Class constructor
- __toString() — Returns a formatted string with a summary of the details of the browser.
- getAolVersion() — The version of AOL.
- getBrowser() — The name of the browser. All return types are from the class contants
- getPlatform() — The name of the platform. All return types are from the class contants
- getUserAgent() — Get the user agent value in use to determine the browser
- getVersion() — The version of the browser.
- isAol() — Is the browser from AOL?
- isBrowser() — Check to see if the specific browser is valid
- isChromeFrame() — Used to determine if the browser is actually "chromeframe"
- isFacebook() — Is the browser from facebook?
- isMobile() — Is the browser from a mobile device?
- isRobot() — Is the browser from a robot (ex Slurp,GoogleBot)?
- isTablet() — Is the browser from a tablet device?
- reset() — Reset all properties
- setAol() — Set the browser to be from AOL
- setAolVersion() — Set the version of AOL
- setBrowser() — Set the name of the browser
- setPlatform() — Set the name of the platform
- setUserAgent() — Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
- setVersion() — Set the version of the browser