Information Technology Reference
In-Depth Information
Figure 6-8. The Download App HTML Page in Safari
Now we have a simple way to route our user to the correct download, without requiring
them to tap on one icon or the other! As you can imagine, we could use this same
detection for other purposes—showing different text to different users, displaying
different advertisements, etc… The best part is that it's all in HTML and JavaScript,
meaning that if you elect to use a product to turn your Web App into a native app
(something we'll discuss in Chapter 13, using tools such as PhoneGap or Titanium
Mobile), you can use this trick to provide a greater level of customization for the user!
Now that we've talked about detecting the User Agent in both PHP and JavaScript, we'll
finish by discussing how we can use the Apache Web Server to do the detection for us.
.htaccess User Agent Detection
These types of files are configuration files commonly associated with Apache web
servers. Also referred to as a distributed configuration file, the .htaccess file can set a
series of rules and configurations to a web application on a per-directory basis. The
.htaccess file can be used to control rewriting the URLs to something much cleaner and
easier to read by humans by using the mod_rewrite module if the server supports it.
Another fun use for the .htaccess file is to use it to detect the user agent string and
direct the user to a different site or sub-domain, if needed. See Listing 6-4.
 
Search WWH ::




Custom Search