2
votes

I am trying to identify and do some study on what user agent is sending request to our application.

when i execute the request in chrome i see that it says

"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"

when i execute it from safari it says

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50

when u execute it from mozilla it says

Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:49.0) Gecko/20100101 Firefox/49.0

Why does it say "Mozilla/5.0" for all requests and for chrome specifically it lists all mozilla, chrome and safari.

Can any one please explain why is this the case? Thanks.

1

1 Answers

2
votes

User agent strings are a mess, and it is very difficult to write code to get accurate information from them. (See this link for a detailed history of why).

If you just want to gather statistics, try adding Google Analytics to your front end, or use a library that specializes in parsing user agent strings on your back end, such as MobileDetect for PHP.

If you want to do something different depending on what features the browser supports, try detecting support for that feature instead of the browser version. Modernizr is great for this.