dongping4901 2015-10-28 20:18
浏览 70
已采纳

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

This question already has an answer here:

I know some very light PHP and decided to start from the ground up and was looking at php.net http://php.net/manual/en/tutorial.useful.php On this page, it mentions in an example how to check for IE.

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

I have a very small test page made up that I'm going through the section here with and this is what I have written down...

<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>

What I don't understand is why when I load this into Internet Explorer, the output onto my screen is Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko and the if statement thus returns nothing. Is there something very basic I'm not getting?

</div>
  • 写回答

1条回答 默认 最新

  • doujishao8793 2015-10-28 20:21
    关注

    IE 11 no longer uses MSIE in the user agent string, it is also bad practice to detect for a browser you should detect for features with libraries like 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮