Skip to content

Instantly share code, notes, and snippets.

@salayhin
Created April 13, 2013 06:35
Show Gist options
  • Save salayhin/5377329 to your computer and use it in GitHub Desktop.
Save salayhin/5377329 to your computer and use it in GitHub Desktop.
How to detect browser version.
$browsers = array(
'firefox', 'msie', 'opera', 'chrome', 'safari', 'mozilla', 'seamonkey', 'konqueror', 'netscape',
'gecko', 'navigator', 'mosaic', 'lynx', 'amaya', 'omniweb', 'avant', 'camino', 'flock', 'aol'
);
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$browser['useragent'] = $_SERVER['HTTP_USER_AGENT'];
$user_agent = strtolower($browser['useragent']);
foreach($browsers as $_browser) {
if (preg_match("/($_browser)[\/ ]?([0-9.]*)/", $user_agent, $match)) {
$browser['name'] = $match[1];
$browser['version'] = $match[2];
@list($browser['majorver'], $browser['minorver'], $browser['build']) = explode('.', $browser['version']);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment