Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing the HTTP header user-agent



I am using the user-agent to store which browser a user is using to access a website. No mission-critical stuff if an occasional mis- classification occurs, as long as its not frequent enough to break the mail statistics.

I did some research on this, and this is what I found out as a "general" rule:

As nearly all browsers will identify themselves as mozilla, many as msie, and a lot as gecko, I have worked out the following

0. convert the user-agent to lowercase.

The following would be implemented as an else-if, so if a 1 is true, neither of the other checks are made. I think I've included all the "major" browsers I could think of. The application doesn't have to be perfect, but good enough. Also if a user is using firefox and set it up to pretend to be IE, I guess its "OK" for me to store it as IE, etc.

Anyone knows a better way to identify different browsers ?

1. check if the user-agent contains the word "googlebot" => "browser" is googlebot
2. check if the user-agent contains the word "links" => browser is Links
3. check if the user-agent contains the word "lynx" => browser is Lynx
4. check if the user-agent contains the word "safari" => browser is Safari
5. check if the user-agent contains the word "opera" => browser is Opera
6. check if the user-agent contains the word "omniweb" => browser is omniweb
7. check if the user-agent contains the word "netscape" or "ns8" => browser is netscape
8. check if the user-agent contains the word "camino" or "chimera" => browser is camino
9. check if the user-agent contains the word "konqueror" => browser is conqueror
10. check if the user-agent contains the word "msie" => browser is most probably IE at this point
11. check if the user-agent contains the word "firefox" => brower is most probably firefox
12. check if the user-agent contains the word "mozilla" => browser is most probably mozilla
13. Browser underermined, "unknown"


/**
* Med Vennlig Hilsen,
* Joachim Haagen Bøe
* @Grad: Bachelor i Informasjonsteknolog, Queensland University of Technology
* @Webmaster: www.devsiden.info, www.haagen.name
*/


On 23/06/2005, at 6:36 AM, Timothy Luoma wrote:


On Jun 22, 2005, at 3:48 AM, Joachim Haagen Bøe wrote:


Does anyone know if there are any good sources for information (preferably with implementation) of ways to parse the user-agent properly ?


There is no good way to browser sniff.

There will always be problems.

For example, Firefox on Mac pretends to be IE... that is to say, it mimics IE's attempts to be seen as "Mozilla" (as just about every browser does).

And then you get Safari which claims to be "like Gecko"

And Opera, which will pretend to be IE which pretends to be "Mozilla"

Really finding IE is nearly impossible, given all the variations of browsers which try to look like it, lest they be blocked out of a site by someone whose brain-dead browser sniffer thinks that they know best what browsers should be "supported"

Browser sniffing is the dark side. Use with extreme caution, and only when forced.

Perhaps if you could say a bit more about what you were trying to do?

    TjL
    President and Founder, Anti-Browser Sniffing Alliance
    Our motto: "Sniff glue, not browsers!"




_______________________________________________ Do not post admin requests to the list. They will be ignored. Web-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden
References: 
 >Parsing the HTTP header user-agent (From: Joachim Haagen Bøe <email@hidden>)
 >Re: Parsing the HTTP header user-agent (From: Timothy Luoma <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.