php - Found it browser is IE Using HTTP_USER_AGENT -
i trying write little script find out type of browser user using.
i found following somewhere (i think so):
$browser = array( 'version' => '0.0.0', 'majorver' => 0, 'minorver' => 0, 'build' => 0, 'name' => 'unknown', 'useragent' => '' ); $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 $_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; } } } var_dump($browser);
out of little code snippets tried, 1 worked best. correctly identified chrome , firefox. however, can't correctly identify ie, (i using ie11) because ie doesnt pass information browser. output above code on ie11 follows:
array(6) { ["version"]=> string(3) "5.0" ["majorver"]=> string(1) "5" ["minorver"]=> string(1) "0" ["build"]=> null ["name"]=> string(7) "mozilla" ["useragent"]=> string(68) "mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) gecko" }
once again, microsoft have throw spanner in works when comes internet explorer. can detect ie? there no msie or indication of internet explorer in http_user_agent. how can detect it?
trident
rendering engine of ie – whenever partial string shows up, can assume you’re dealing internet explorer (or trying fake one, of course).
Comments
Post a Comment