26

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?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
botenvouwer
  • 4,334
  • 9
  • 46
  • 75

2 Answers2

37

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.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • is it possible for users to obscure their UA string altogether? i recently built a site whereby i collect the UAS of visitors, but it seems a lot of the bot activity that visits my site dont use UAS? – oldboy Aug 09 '19 at 04:31
  • Yes, very possible. It's just a string that a browser optionally sends to the server. Firefox can let you change the string entirely via the `about:config` page by modifying/creating the string `general.useragent.override` with your new user agent. I don't see why you would want to unless you're experimenting with code. – nxasdf Nov 28 '19 at 01:46
15

http://www.useragentstring.com/

Visit that page, it'll give you a good explanation of each element of your user agent.

Mozilla:

MozillaProductSlice. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore

Prash
  • 1,915
  • 3
  • 20
  • 32