s7ven
s7ven

Reputation: 183

How to detect really IE when changed user agent

In my project have use PHP to detect browser, but my customers used IE11 and change User agent to IE7. And my customer required detect is IE11, not IE7. IE 11

Please help me detect really IE11

Upvotes: 1

Views: 220

Answers (1)

rocky
rocky

Reputation: 631

Check using 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.$1);
        }
        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.$1);
        }
        return ieVr;
    }

As per Doug in 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
    }   
}

Upvotes: 1

Related Questions