Mark Pilgrim reports that the new Safari web browser for Mac reports its User Agent (UA) string to be this:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/48 (like Gecko) Safari/48
I have already written about the evil twisted path of UA sniffing but let me summarize again, because clearly some people still don't get it.
UA sniffing is a bad idea.
Don't believe me? WebStandards.org: Dear Web Developers: Browser Sniffing is Stupid
Why is sniffing stupid?
Short answer: Browsers lie.
Medium Answer: Web designers made bad decisions by starting to UA sniff a long time ago and that made web browser programmers determine that they had to lie.
Long answer: Read my link above.
Once again, here is Opera 7's default UA string on Windows XP:
Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.0 [en]
Reading from right to left that says: Hey, this is Opera 7 pretending to be Internet Explorer 5.5 or Internet Explorer 6.0 (some dumbos sniff for MSIE 5.5 and block MSIE 6.0 and tell you to upgrade your browser!) or Mozilla 4.0. Mozilla is Netscape's name for Netscape. Except now there is a browser called Mozilla, but it isn't called Mozilla in the UA string, well it is, but it's really called Gecko because EVERYONE presends to be Mozilla.
ARGH!
Stop the insanity!
Stop UA Sniffing!
Support web standards!
Some folks who ought to know better (including Mark Pilgrim, who almost always knows better) were caught by Safari because it uses the word "Gecko" in the UA string. Everyone assumed that "Gecko" would be sacrosanct in the UA string to mean "This really is a Gecko based browser."
As of today, that assumption no longer holds water.
The Netscape/Mozilla folks really ought to be pleased with themselves, they have created not one, but two UA strings that everyone wanted to pretend to be... first it was Mozilla because Netscape supported tables before IE did (so when IE supported it, they found they were locked out of some sites because looked at the UA string for the word "Mozilla", and now Gecko because everyone considers it to be the premier rendering engine.
Some folks who ought to know better, folks who support web standards and want to get away from hacks, were tripped up by this, because they were UA sniffing to serve pages as application/xhtml+xml. This is wrong, wrong, wrong!!! If you want to sniff for something, use the HTTP_ACCEPT.
There is no reason for any browser to lie in the HTTP_ACCEPT header, and it is there to tell you what it can handle.
Want to be able to set the MIME type using HTTP_ACCEPT and PHP?
<?php
$ACCEPT = $_SERVER["HTTP_ACCEPT"];
if (strstr($ACCEPT,'application/xhtml')) {
header("Content-type: application/xhtml+xml");
}
?>
Use that and you will not have to go back and check the UA string for every new browser that comes out... sort of like writing to web standards and not having to worry about checking your HTML in every browser that comes out.
I would like to THANK Apple for doing this, because it helps to expose (again) what a really really bad idea it is to depend on the UA string for anything!!!
Are you ready to admit your UA sniffing addiction and pledge to try and quit cold turkey? If so, add a comment to this post... maybe we'll start a support group.