Thanks to Microsoft (and Netscape, but mostly Microsoft), 90% of browsers identify themselves as something else. This makes life hard.
In the early days of the web, everything was fine. Browsers identified themselves in a sane manner. The most well known browser was Mosaic.
Along come Netscape with their ‘Mosaic-Killer’ browser. To web servers it identified itself as Mozilla (mosaic-killer->mozilla, geddit?). At this time, Netscape was inventing extensions to HTML, that no other browser understood, so often authors wrote 2 different versions of pages. Standard and ‘Netscape Enhanced’.
Microsoft introduced Internet Explorer, but people obviously wouldn’t switch if it couldn’t display all their favourite Netscape-enhanced pages properly. Because of this Internet Explorer identified itself (and still does) in the form Mozilla (compatible; MSIE), so that it received the same pages as Netscape.
To get over the same problem Opera identifies itself by default in the form Mozilla/4.0 (compatible;MSIE;Opera). So to get accurate statistics, you’ve got to look for Opera before IE, and IE before Netscape.
The modern Mozilla browser can’t identify itself as Mozilla/version, because then it receives pages saying ‘You’ve got a very old Netscape, we won’t let you in until you upgrade. Mozilla therefore does something like this – Mozilla/5.0 (rv:1.7) . Netscape 6 and above, are based on this competely different Mozilla, and do something similar to Mozilla/5.0 (rv:1.7) Netscape/6. Other Mozilla-based browsers do the same e.g. Mozilla/5.0 (rv:1.7) Firefox/1.0.
So…
The number after Mozilla/ is the version of Netscape in versions 1-4. But you’ve got to check for Internet Explorer & Opera first. For Netscapes 6 and up, you need to look for Netscape/. This needs to be done before checking for plain Mozilla, as does checking for Firefox etc…as you amass a list of browsers, the amount of ‘check this before that’ requirements for accurate identification of the browser is staggering.
I’ve rewritten parts of this multiple times to make more sense, apologies if it still doesn’t.