PHP - 检查 IE,了解 $_SERVER['HTTP_USER_AGENT']

PHP - Checking for IE, understanding $_SERVER['HTTP_USER_AGENT']

我知道一些很轻的东西 PHP 并决定从头开始并正在研究 php.net http://php.net/manual/en/tutorial.useful.php 在此页面上,它在示例中提到了如何检查 IE。

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
    echo 'You are using Internet Explorer.<br />';
}
?>

我制作了一个非常小的测试页,我将使用它来完成此处的部分,这就是我写下的...

<html>
    <head>
        <title>PHP startup testing page</title>
    </head>
    <body>
<?php 
        echo "<p>Hello World</p>";
        echo $_SERVER['HTTP_USER_AGENT']; //outputs the kind of browser the visitor is using.
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
            echo 'You are using Internet Explorer.<br />';
        }
?>
    </body>
</html>

我不明白的是为什么当我将其加载到 Internet Explorer 时,屏幕上的输出是 Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) 像 Gecko 和 if 语句因此 returns 什么都没有。有什么非常基本的东西我没有得到吗?

IE 11 不再在用户代理字符串中使用 MSIE,检测浏览器也是不好的做法,您应该使用 Modernizer https://modernizr.com/, here is a link on IE 11 user agent strings https://msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx

等库检测功能