Detecting IE browser version using PHP

I am using $ _SERVER ['HTTP_USER_AGENT'] to detect a custom browser. When I run var_dump on my localhost in IE8, it returns: ... compatible; MSIE 8.0; ... But when I download it to my host (godaddy), I get: ... compatible; MSIE 7.0; ...

What is the problem?

+3
source share
4 answers

Check the word TRIDENTon the line. Compatibility is in compatibility mode. Google if you want to know what that means. However, the term trident is only ie8 +.

: , /, ie8- ( ). , , . Google .

+2

$_SERVER ['HTTP_USER_AGENT']

, . .

User-Agent string-hacking - . , .

: IE8, , IE7. Trident/... , , , , , , , User-Agent IE , , , , , .

, , HTTP , , , - , Vary . , IE.

UA - , , - . IE .

+9

get_browser() , .

:

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);
?>

:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3

Array
(
    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
// ...
+1
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
echo $version = $matches[1];
-1

Source: https://habr.com/ru/post/1754035/


All Articles