Chapter 7. Switching Between Mobile and Desktop Browsers

WHAT'S IN THIS CHAPTER?

  • How to interpret the HTTP headers that mobile devices use to request content from web servers

  • Developing a simple detection algorithm that will allow the web server to distinguish between different types of requesting browsers

  • Creating a switching algorithm that will present different sites — or versions of the same site — for mobile devices

In Chapter 6, you looked at different entry points and building different sites for mobile and desktop users. One piece of the jigsaw alluded to was being able to detect the browser and decide which of the two types it belongs to.

In this chapter, you look at exactly how you can do this in a reliable and efficient way. You also create some algorithms that allow users to override the results of your detection for when the detection has made an incorrect identification or for when the user would like to switch to the other type of device's content.

Throughout this chapter, the code examples are presented in PHP, not because this is the only language that can perform such detection, of course, but simply because that allows the code to be relevant to the three major Content Management System (CMS) platforms discussed later in this book.

BROWSER DETECTION

The days of the homogenous web browser audience are long gone. On the desktop, Netscape Navigator, and then Microsoft Internet Explorer, have both enjoyed periods of market dominance, and web developers could be forgiven for ...

Get Professional Mobile Web Development with WordPress®, Joomla!®, and Drupal® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.