Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does HTTP_USER_AGENT function? [duplicate]

When I get the PHP server variable HTTP_USER_AGENT with this code:

<?php    $useragent = $_SERVER ['HTTP_USER_AGENT'];    echo "<b>Your User Agent is</b>: " . $useragent; ?> 

I get this in Google Chrome:

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

This in Firefox:

Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0

And this in IE:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;NLNL)

My obvious question is: how does this work? Why does my user-agent say Mozilla and Windows NT while I am using Google Chrome?

Also, why does it say that I use Firefox when I am using IE?

like image 950
botenvouwer Avatar asked Nov 06 '12 13:11

botenvouwer


1 Answers

The user agent string is a text that the browsers themselves send to the webserver to identify themselves, so that websites can send different content based on the browser or based on browser compatibility.

Mozilla is a browser rendering engine (the one at the core of Firefox) and the fact that Chrome and IE contain the string Mozilla/4 or /5 identifies them as being compatible with that rendering engine.

like image 98
Roy Dictus Avatar answered Oct 19 '22 08:10

Roy Dictus