51Degrees.mobi device detection with the Zend Framework and Zend Server


10/2/2012 4:13 PM

Device Detection PHP Development

In this short guide, I will show you how to implement the The 51Degrees.mobi PHP device detection API into a Zend framework project running on a Zend application server. Although this article has been written with Zend server in mind, the principals will apply to any other PHP compatible application server.

Note: When mentioning the "document root" of your web server, we are referring to the "wwwroot” folder usually found in C:/inetpub/wwwroot on a Windows machine.

1) Download the 51Degrees.mobi PHP zip file.

You can find the latest zip file containing the PHP API here. There is also a general setup guide located here.

2) Unzip the file into your document root.

As mentioned above, this is the “wwwroot” folder if you are using Zend Server.

3) In your Zend project, add the following includes:

51Degrees\51Degrees.mobi.php 51Degrees\51Degrees.mobi.usage.php

This second line is optional, but it helps with the ongoing development of 51Degrees. Replace the first part of each line ("51Degrees\") with the path to your 51Degrees.mobi PHP folder

4) Call the 51Degrees.mobi detection function.

Use the variable $_51d[“Property”] to obtain information about the connecting device. This can be used from anywhere within your Zend Framework application, provided you have included the 51Degrees.mobi PHP files. For example, to detect whether the device is mobile (possible with the free open source version of the API) you would use the following code:

<?php $IsMobile = $_51d == "True"; if($IsMobile) // Behavior if device is mobile else if (!$IsMobile) // Behavior if device is not mobile ?>

5) Modify to suit your needs.

To get the most from the 51Degrees.mobi API, check out the property dictionary here to see the full list of properties available to both the Lite and Premium versions of the software.