Differentiating Based on USER_AGENT

Throughout this chapter, we have talked about how you can build applications that work well on multiple devices by taking the time to identify exactly what device is accessing your application. This is a simple thing to do and can be accomplished in any programming language that you prefer to work with. The key to identifying the client is flexibility and open-ended pattern matching. Although it would be very difficult, and nearly impossible, for you to differentiate your application for every WAP device on the market, you are best served by focusing on three cases. The three "super classes" of devices that you should take the time to consider are the UP.Browser from Phone.com (which can be found in devices from over 25 different manufacturers), the Nokia 7110 and Ericsson R320 (which have similar user interfaces), and then a catch all for everything else.

Working with the HTTP_ACCEPT Header

Keeping track of all USER_AGENT strings and new devices on the market is an impossible task, and fortunately, you don't need to do it because traditional WWW sends out a very short list and handles most content locally by sending */* ("I'll take anything").

HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

Real WAP devices will send out text/vnd.wap.wml in the ACCEPT HTTP header. You can use this to identify a WAP client no matter what the USER_AGENT header looks like. This absolves you from having to keep up with each new device that hits the market.

Working with the USER_AGENT Header

Now that you have identified that a WAP client is accessing your site, discovering additional information about the client is a simple task. By looking for one of three things in the USER_AGENT string, you can recognize the three major WAP browser vendors, Nokia, Ericsson, or Phone.com. Simply pattern-match for "Nokia", "Ericsson", or "UP.Browser" in the USER_AGENT string. An example of this is provided in the idUserAgent subroutine in the Perl code listing in the Working with Different Devices section of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.111.24