更改用户代理时如何检测真正的 IE

How to detect really IE when changed user agent

在我的项目中使用 PHP 检测浏览器,但我的客户使用 IE11 并将用户代理更改为 IE7。我的客户要求检测的是 IE11,而不是 IE7

请帮我检测一下真的是IE11

使用 JS 检查

function checkIE()
    {
        var ieVr = -1;
        if (navigator.appName == 'Microsoft Internet Explorer')
        {
            var agent = navigator.userAgent;
            var exp = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (exp.exec(agent) != null)
                ieVr = parseFloat(RegExp.);
        }
        else if (navigator.appName == 'Netscape')
        {
            var agent = navigator.userAgent;
            var exp = new RegExp("Trident/.*ieVr:([0-9]{1,}[\.0-9]{0,})");
            if (exp.exec(agent) != null)
                ieVr = parseFloat(RegExp.);
        }
        return ieVr;
    }

根据 PHP

中的道格
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if(count($matches)<2){
  preg_match('/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
}

if (count($matches)>1){
  //Then we're using IE
  $version = $matches[1];

  switch(true)
    {
    case ($version<=8):
      //IE 8 or under!
    break;

    case ($version==9 || $version==10):
      //IE9 & IE10!
    break;

    case ($version==11):
      //Version 11!
    break;

    default:
      //You get the idea
    }   
}