doukuanjing5404 2013-07-30 08:43
浏览 156
已采纳

仅使用PHP检测IE兼容模式

Is it possible to detect that IE is in compatibility mode from the useragent with PHP?

I use IE10 and have the useragent

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)

So it appears as Internet Explorer 7 then.

Sure, It would be a bad idea to rely on only such a detection by PHP, but it is very useful for some ocasions (for example logging with PHP or debugging-hints,...)

  • 写回答

2条回答 默认 最新

  • douba5540 2013-07-30 08:47
    关注

    From this resource: http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx

    To detect IE 10 in compatibility mode rather than a regular IE 7 you should look at the token Trident/6.0 which identifies IE 10 regardless of the mode.

    To detect it from PHP, grab the user agent from the headers and parse it for the Trident/6.0 string token.

    You can recognize more versions of Internet Explorer from the Trident token: IE9 has Trident/5.0, IE 8 has Trident/4.0, IE 7 has no Trident in it's user agent.

    The user agent string can be found at $_SERVER['HTTP_USER_AGENT']. From there it's trivial as to search a substring inside or with a regex.

    IE10 User agent reference:

    • normal mode: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
    • compatibility mode: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0)

    Note that the MSIE token is different but the Trident token is the same. This is the indication that the user has compatibility mode enabled.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答