0

I am trying to do some php browser testing. When I looked at

$_SERVER['HTTP_USER_AGENT'

I found that it returned this:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

even though I was on IE 11.

When I was on Chrome, it returned this:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36

Which makes more sense. Why is there no MSIE in the IE, and how can I target it?

user1015214
  • 2,733
  • 10
  • 36
  • 66
  • 2
    with the Trident tag. Its the IE engine. Check this http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx and also this http://en.wikipedia.org/wiki/Trident_(layout_engine) –  Oct 06 '14 at 16:20
  • http://en.wikipedia.org/wiki/Comparison_of_web_browser_engines – PeeHaa Oct 06 '14 at 16:21

3 Answers3

5

"Trident" is the layout engine for MSIE 11. As you can see there, while you were on IE 11 it loaded as Trident/7.0; rv:11.0) Just like when you were on Chrome it loaded as AppleWebKit/537.36.

If you're looking to get more information about the browser, you could always use PHP's get_browser() function.

helllomatt
  • 1,331
  • 8
  • 16
  • technically, its the layout engine from MSIE8 –  Oct 06 '14 at 16:25
  • @oPi, you're right. However, it's still listed as being a part of IE11 in the ["Versions"](http://en.wikipedia.org/wiki/Trident_(layout_engine)#Versions) section of the Wikipedia page. – helllomatt Oct 06 '14 at 16:27
  • LOL, it was my bad. I read "is the layout engine from MSIE 11". Sorry –  Oct 06 '14 at 16:33
1

its because the MSIE from 8 marks its version through TRIDENT. Ive found this script time ago. It also detects if the browser is in compatibility mode. It may help you, but its in JS:

EDIT: a simple search made i found the original code in github.

var ieUserAgent = {
    init: function () {
        // Get the user agent string
        var ua = navigator.userAgent;
        this.compatibilityMode = false;
        // Detect whether or not the browser is IE
        var ieRegex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (ieRegex.exec(ua) == null)
            this.exception = "The user agent detected does not contain Internet Explorer.";

        // Get the current "emulated" version of IE
        this.renderVersion = parseFloat(RegExp.$1);
        this.version = this.renderVersion;

        // Check the browser version with the rest of the agent string to detect compatibility mode
        if (ua.indexOf("Trident/7.0") > -1) {
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
            }
            this.version = 11;                  // IE 11
        }
        else if (ua.indexOf("Trident/6.0") > -1) {
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
            }
            this.version = 10;                  // IE 10
        }
        else if (ua.indexOf("Trident/5.0") > -1) {      
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
            }
            this.version = 9;                   // IE 9
        }
        else if (ua.indexOf("Trident/4.0") > -1) {
            if (ua.indexOf("MSIE 7.0") > -1) {
                this.compatibilityMode = true;
            }
            this.version = 8;                   // IE 8
        }
        else if (ua.indexOf("MSIE 7.0") > -1)
            this.version = 7;                   // IE 7
        else
            this.version = 6;                   // IE 6
    }
};

// Initialize the ieUserAgent object
ieUserAgent.init();

$(document).ready(function() {
    if(ieUserAgent.compatibilityMode) {
        //do stuff
    }
    if(ieUserAgent.version == 6) {
        //do stuff
    }
});
1

IE11 drops the "MSIE" portion of the user agent string. It doesn't stop there, either - navigator.appName will return Netscape and navigator.product returns Gecko.

The likely cause for this is that IE11 has caught up enough with modern web standards that Microsoft doesn't want it triggering the old if(IE) { // shitty simpler website } handlers all over the web. They want it seeing the same full-featured version Chrome/Firefox see.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368