July 04, 2009   Login   |   Register  
  Search  
  |  
  Tips & Tricks | Developers Corner | HTTP_USER_AGENT

Using the HTTP_USER_AGENT

Minimize
Solving problems | The 1st problem  | The 1st solution  | Getting the info you need to decide | Explaining the mess (1) | Explaining the mess (2) | Explaining the mess (3) | Sorting through bullshit | Damage control... | Identifying OSes | So far, so good... | The Plugins... | A Guiding "Stragedy" | OS order | Alienating users | Mac Users | Linux Users | Windows Users | Final Words...
 
 

Solving real-world problems

This article focuses on working with and using the HTTP_USER_AGENT to solve complex real problems where you want to serve up serious cutting-edge content like video or complex multi-media.

 


Summarizing the 1st problem

Since not all browsers or operating systems support all HTML tags or plugins, and not all clients have all plugins installed, designing advanced or cutting-edge content that works in all browsers can be difficult and in some cases, impossible. The best that you can do it to come up with content where the HTML is as cross-browser compliant as possible. This doesn't help for plugins though.

For example, Mac computers don't have Windows Media Player installed, and most Windows computers don't have Quicktime installed. God only knows what happens on the 30 trillion flavors of UNIX, Linux, and BSD.

How can you serve up multi-media content that will make them all happy, and still maintain control over the presentation?

 


Summarizing the 1st solution

By using standards compliant HTML, and serving up customized content for different operating systems, you can deliver cutting-edge multi-media content that caters to specific clients, and maintain control by knowing ahead of time what you will be serving.

 


Getting the info you need to decide

As we saw in the HTTP Headers article, getting headers is very simple. This is what you need to specifically get the user agent:

Request.ServerVariables("HTTP_USER_AGENT")

And it's the same in both ASP and ASP.NET.

Once you've got the user agent string, the hard work starts. For a quick peek at what kind of values you can get returned to you in the user agent string, have a quick look at the article on 5.1 Audio on the Web. They're messy - VERY messy. Many of them lie about who they are, and the format is not standardized. Yuck.

 


Explaining the mess (1)

There is no standardization for user agent strings. Although they follow a general pattern, this is not adhered to by the different user agents. Many in fact lie about who they are, or at least try to trick us into thinking they are something other than they are.

Here are a few examples of Windows computers using Internet Explorer:

  • Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
  • Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)
  • Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)

And here are some that try to make us think that they are the same:

  • Mozilla/4.0 (compatible; LINUX MSIE; Linux Fedora Core 1)
  • Mozilla/4.0 (compatible; MSIE 5.0; Linux)
  • Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows 98) Opera 7.21  [nl]
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; NetCaptor 7.5.0 Gold; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Rogers Hi-Speed Internet; Crazy Browser 1.0.5; .NET CLR 1.0.3705)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2) Opera 7.11 [en]
  • Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera 7.23  [en]
  • Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera 7.50  [en]

It should be patently obvious what's going on here, but since that explanation is a total cop-out, I'll explain each part later. But for the time being, just take note of the obvious things like "Linux", "Mac_PowerPC", "Opera", and "X11". Those are clearly not Internet Explorer even though they identify themselves as IE with "MSIE".

 


Explaining the mess (2)

So far we know that user agents lie. e.g. Internet Explorer does not run on Linux. We also have a definite pattern to how the user agent string is made. Time to shatter that...

  • Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/85.7 (KHTML, like Gecko) Safari/85.5
  • Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.6b) Gecko/20031208
  • Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
  • Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.5) Gecko/20031107 Galeon/1.3.11a (Debian package 1.3.11a-1)
  • Opera/7.x (compatible; Konqueror/2.2.2; Linux 2.4.14-xfs; X11; i686)

The first 4 follow a definite pattern, while the last is more similar to the ones above. So what are we to make of it?

 


Explaining the mess (3)

Years ago when Netscape was the dominant browser, user agent strings were used to serve up different content for Netscape, which at the time had some additional goodies that IE was lacking. In the race to catch up, IE started using similar user agent strings to trick servers into giving up the same content. The whole thing escalated with every Tom Dick and Harry browser doing the same thing - mimicking Netscape by starting the user agent string with "Mozilla", but adding in their own brand after the IE identification, "MSIE".  Let's examine the following 3 mimics:

  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; NetCaptor 7.5.0 Gold; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Rogers Hi-Speed Internet; Crazy Browser 1.0.5; .NET CLR 1.0.3705)
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2) Opera 7.11 [en]

The bold blue tells us that the browser is the Mozilla code base, or Netscape. The bold brown tells us that it is Internet Explorer (and for these 3 examples, version 6). The bold red gives the real name of the user agent.

Just remember that the "b" in blue and the "b" in brown both stand for "bull", as in "bullshit". The "r" in red stand for "real".

 


Sorting through bullshit

We know that we can't reliably test for Netscape browsers by relying on it to start with Mozilla, and we can't reliably determine that a browser is Internet explorer just because we find "compatible; MSIE 6.0;" in the user agent string.

That's just half of it though. We still have to check for different OSes. But all things in good time...

Question: So, how can you determine if you have NS or IE?

Answer: Don't test for major browsers (NS & IE). Test for other browsers and eliminate.

Problem: Some will fall through the cracks because you can't possibly keep track of every browser and OS out there.

 


Damage control...

So, the real situation isn't about actually about always serving the right content to every client, it's more about damage control.

The first line of defense is determining the OS. This lets you automatically eliminate browsers.

e.g. Safari is Mac OSX only. IE doesn't run on Linux, Sun, or UNIX systems. Neither Konqueror nor Galleon run on MS or Mac systems. And nobody even cares about Lynx anymore anyways...

So let's have a quick look at how to identify operating systems...

 


Identifying OSes

The web is merely a numbers game, and since there are only a limited number of operating systems that are important, our task here is simplified greatly.

There are two ways to identify OSes:

  1. Directly by something that tells us what the OS is
  2. Indirectly by something that only runs on a specific OS

It is unlikely that the Joe Blow OS will identify itself as Major Star OS, so if we know a few of these, and their capabilities (as far as their browsers go), then we can eliminate them and serve up some default "Joe Blow" HTML content. (This is direct detection.)

Once we have those covered, we can focus on the major OSes... who are...

  1. Microsoft Windows (about 91%)
  2. Apple MacIntosh (about 4%)
  3. Linux (about 1%)
  4. Other & Jow Blow OS (about 4%)

Again, we need to do damage control for that 4% that use the Joe Blow OS first before anything else.

So the question is, how do they all identify themselves? Again, we need a list to help identify these OSes through direct OS detection.

 


So far, so good...

So what?

What we need so far is a list of OSes and browsers. There are a lot of lists out there on the internet, but there are always new OSes and browsers being introduced, if not in name, then in version and capabilities.

But there's one more list of what we need...

 


The Plugins...

And so for each OS and for each browser, we need a list of plugins that work in that environment.

Yikes.

 


"Stragedy"

In the immortal words of Bugs Bunny, we need a "stragedy".

But "foist" (Bugs Bunny accent required for correct prununseeashun), we'll list our parameters:

  • Different OSes
  • Different user agents (browsers, spiders, robots, etc.)
  • Different plugins

Our options are to spend LOTS of money on detection software ($1,000+) or opt for a simple strategy that we can maintain and expand.

So... We'll target major OSes, major browsers, and major plugins. We can cover greater than 99% of all combinations with an intelligent routine.

The major OSes:

  1. Windows
  2. Mac
  3. Linux

In that order.

The major browsers:

  1. Internet Explorer
  2. Netscape
  3. Opera
  4. Firefox

Roughly in that order, but that is changing rapidly.

The major plugins:

  • Flash
  • Adobe Acrobat Reader
  • Windows Media Player (6.4, 7, 9, 10)
  • Real Player
  • Quicktime

In no particular order, but roughly about right.

Since both Flash and Acrobat Reader are cross platform, is doesn't matter how we treat them, but the other 3 matter.

The Strategy

We'll prioritize OSes, then user agent, then plugin.

 


Macs first

Macs are simple. Just serve up Quicktime content. It's a no brainer.

Once you've determined that you have a Mac, you can fiddle around, but there is no reason to.

Linux next

Once the Macs are taken care of, the next problem is Linux. Here, you'll have to fool around with the plugin that you want to use. Since most browsers on Linux are Mozilla based, you can pretty safely assume that you've got either Netscape, FireFox, Konqueror, Galleon, or something similar. At the end of the day, you'll end up marginalizing a lot of these users unless you want to put in a huge amount of effort. For the sake of ease, you can only play into browser, which is actually very easy to do. Just stick in an embed then let their browser take care of the rest. This isn't a bad thing, because most of these users are far more knowledgable that other OS users. If they have problems viewing your page, they can probably fix it pretty easily.

Windows last

There are just far too many options on Windows, and this is where things become difficult. This is where you really need to pay attention to both the browser and the plugin. Keeping these people happy will not be fun.

 


Alienating users, or... who cares?

Since Macs are so easy to deal with, it's pretty hard to alienate them with content they can't view. The problem come with the Linux and Windows users.

For Linux, you actually don't need to worry too much. Their browser should take care of things as long as you serve up industry standard content. For audio, this is going to be MP3 or WAV. Since WAV files are massive, you'll be best off serving up MP3 content.

Video is tougher. All the good video codecs/format require royalties from the players, and raw video formats are too large. AVI is a good standard, but it's from MicroSoft. MPEG-1 might be a better choice to these users even though it is fairly large. You may need to opt for Flash at this point, but that is cross-platform, and we are not too interested in that for this discussion.

Windows opens a whole new can of worms. Some people still use Windows 95, but this is a very small segment.

 


Mac Users

Once you've determined that you're serving content to a Mac client, just stick in a QuickTime chunk of code. The Mac will take care of the rest.


Linux Users

Just as with the Macs, just stick in an embed and let the Linux box take care of it. Since Linux users tend to be more knowledgable than others, if they need a plugin, they can take care of it. With so many different Linux distros out there, you can't cover them all, so don't try.


Windows Users

This is the largest segment, and the most complex. Windows users have many choices of browsers that users in other OSes simply don't have. Rather than focus on Windows at this point, we turn to browsers and the mirad of variations (read: problems) they present.


Ok... this is just going on too long...

My apologies for not finishing this, but I've had this article “in progress” for months now, and just don't have time to finish it. I'm just publishing it because I'm sick of it.

Suffice it to say that the above should provide enough information for you to lay out a grid of OSes and browsers to return the right content. Use regular expressions for matching, and select case statements for easy managment.

If you have any specific questions, please visit the Support page to emaiil me.

Cheers,

Renegade

 

 Print   
     
Renegade Minds Web Media Basics  | 5.1 Audio on the Web | Email Avenger  | Web Form Submitter | HTTP Headers | HTTP_USER_AGENT

  Search

Copyright 2008 by Renegade Minds   |   Privacy Statement   |   Terms of Use
Renegade Minds