Detecting Browser Type Using User Agent Strings

Browser DetectiveThis table is a cheat sheet for determining which browser engine a visitor is using, although this can be alterered by the visitor or by antivirus software, etc., so is not going to always be reliable or fool-proof.

Some browsers will report multiple user agents or other browser’s user agents, and so for Firefox, Chrome and Safari we must check that another user agent string is not present, to avoid a false positive.

 

BROWSER Engine Must contain Must not contain
Firefox Firefox Seamonkey
Seamonkey Seamonkey
Chrome Chrome Chromium
Chromium Chromium
Safari Safari Chrome or Chromium
Opera 15+ (Blink-based engine) OPR
Opera 12- (Presto-based engine) Opera
Internet Explorer 10- MSIE
Internet Explorer 11 Trident

 

Example use in JavaScript:

if ( navigator.userAgent.indexOf("Firefox") !== -1 && 
     navigator.userAgent.indexOf("Seamonkey") === -1 )
{
     // We can assume this visitor is using Firefox, 
     // as it contains the word Firefox but not the word Seamonkey.
}

Example use in PHP:

if( stripos($GLOBALS["useragent"], "Chrome") !== FALSE &&
    stripos($GLOBALS["useragent"], "Chromium") === FALSE )
{
    // Here we can assume the browser engine is Chrome, as it
    // contains the word Chrome but not the word Chromium.
}

Leave a Reply