You need to filter out the others in this microverse who'll
tell you that you can't rely on the user agent.
That would be a stupid position to take. A more reasonable potion would
be to try to understand why these things are being said, by asking if
necessary.
The theory of trying to use a browser's User Agent header (or the
corresponding navigator.userAgent string) in order to identify the
browser, its version, and possibly the OS and its version, implies that
each and every browser provides a unique, consistent and immutable
sequence of characters in that header, that contain or imply all of the
necessary information. Then all you need to do is find out the UA header
of every browser that ever has and ever will exist and write a script
that examines them extracts the required information.
The reality of User Agent headers is that the HTTP 1.1 specification
requires no more than that the User Agent send such a header. There are
no technical requirements on the contents of that header; it is
effectively specified as being any arbitrary sequence of characters that
do not even have to be consistent over time. This is what makes it
technically bass-less to speak of browsers/users telling lies; no lies
can be told because there are no criteria for a 'correct' sequence of
characters in a User Agent header.
It is unusual for the User Agent headers used by web browsers not to be,
to some degree, designed to imitate the User Agent headers of other
browsers, and quite common for this to be carried to a point where a
browser's User Agent header is indistinguishable form the User Agent
header of another. For example, Web Browser 2, running on the Palm OS,
used the header "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)", from
which it is impossible to deduce the browser, its version or the OS
being used (and the results of the attempt, while certainly appearing to
be successful, will be actively misleading).
In many cases the user Agent header is user configurable, either
absolutely or by making s selection form alternatives, and the browsers
that offer no mechanism for modification tend to also be the ones that
deliberately set out to send User Agent headers that are
Indistinguishable from those of other browsers.
They don't live in the real world
The real world is the one where there is not formal requirement that
User Agent headers be any more than an arbitrary sequence of characters,
where real browsers deliberately send User Agent headers that are
indistinguishable from the User Agent headers of other browsers and the
users are capable of modifying (some of) those headers in anyway they
choose, and cannot be faulted for doing so because there are not doing
anything contrary to the formal requirements of HTTP.
Is the person living in the real world the person looking at strategies
for dealing with the reality of what a User Agent header is (by
specification and in reality, that is, not a source of information), or
someone working to a theory that these things are unique, consistent,
informative and discrimination, regardless of the evidence?
and have the luxury of telling their employers "NO" to
any request to produce code that would require looking
at the user agent string.
Is there such a thing as "code that would require looking at the user
agent string"? Or are there real problems where looking at the user
agent header might look to some like a solution, so long as they don't
perceive the reality of the situation, but to which there may be (and
hopefully will be) alternative applicable strategies?
After all, if the problem as stated is; 'I need to discriminate between
the sources of arbitrary sequences of characters by examining the
sequences of characters they produce' then the reasonable response to
the person making that specification is that achieving their requirement
is a logical impossibility. Going of an writing software would be
unprofessional, unsuccessful, and ultimately dishonest.
Those of us that have to live with reality know that
the user agent is the best info we've got
The User Agent header is not information at all, by specification. You
may not see yourself as having anything better, but that still does not
make it into information.
and does the job as well as we need it to.
We only need to do the job badly? Well, people certainly can get way
with doing the job badly (and very many do).
I've tried staying out of the threads they had about
it because they were just back and forth amongst themselves.
Mostly because the people taking the pro-browser sniffing position find
it nearly impossible to narrow down to the specifics of there real
problems, and so cannot be shown what may be possible.
When I see them force that diatribe on an unsuspecting noob
like yourself then I don't want to let them convince you
(with the two replies so far) that you can't do anything.
Who said nothing can be done? The specifics of the problem have not been
exposed, just one proposed solution. All that has been said that that
the proposed solution to the unnamed problem is a non-starter.
You can do something and it's better than nothing.
Don't you recognise the possibility that dong the wrong thing can easily
be worse than doing nothing?
I'm assuming you have a genuine need for it and can't do
feature detection.
Why assume that, without any specific information. After all, someone
asking about user Agent strings is clearly ignorant of pertinent aspects
of User Agent strings and attempting to apply a strategy that was
recognised as non-viable a decade or so ago. It makes no sense at all to
assume that such an individual has performed a complete and informed
analysis of their problem.
Richard.