A
Anno Siegel
[...]
Before one can think of a method, there would have to be a way to
identify the OS name. There doesn't seem to be much rhyme or reason
in the samples above (even ignoring the line beginning "Microsoft-Web...".
Neither is it always the third semicolon-separated item in (), nor is
it always the last one.
The only way I see is to have a collection of patterns that match
possible OS names (like /^Windows/, /^WinNT/, ...). Split the part
in parens on /;\s*/ and see if one matches. Resort to guessing if
none of the expected OS names is found. Mark the guesses as such, so
you can update the pattern collection if something new appears.
Anno
Can I rephrase the question please! Could someone show me a better way
to get the OS out of the User-Agent please?:
Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Microsoft-WebDAV-MiniRedir/5.1.2600
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)
Mozilla/4.08 [en] (WinNT; U ;Nav)
Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)
Before one can think of a method, there would have to be a way to
identify the OS name. There doesn't seem to be much rhyme or reason
in the samples above (even ignoring the line beginning "Microsoft-Web...".
Neither is it always the third semicolon-separated item in (), nor is
it always the last one.
The only way I see is to have a collection of patterns that match
possible OS names (like /^Windows/, /^WinNT/, ...). Split the part
in parens on /;\s*/ and see if one matches. Resort to guessing if
none of the expected OS names is found. Mark the guesses as such, so
you can update the pattern collection if something new appears.
Anno