• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Using the Detector - Version 3

All the requesting device properties are stored in the variable $_51d which is populated simply by including the 51Degrees PHP Device Detector script:

<?php
require_once 'path/to/core/51Degrees.php';
?>

$_51d is an associative array built for every requesting device. By using a 51Degrees property name as a key $_51d will return a value or an array of values representing the relevant property value.

<?php
// get if the device is a mobile
$is_mobile = $_51d['IsMobile'];
// will be TRUE or FALSE

$hardware_name = $_51['HardwareName'][0];
// hardware name returns an array, 
// so use [0] to get first value
?>

IsMobile returns a boolean value because it is a boolean type. A full list of properties and their types can be found in the Property Dictionary. If you wish to use the old behaviour of returning a string for every property, set $_fiftyone_degrees_return_strings = TRUE in the 51Degrees.php file.

HardwareName is what is known as a 'list' property (HardwareName property is only available with Premium and Enterprise data files). Some properties can have several values simultaneously that are all returned in an array. HardwareName may have several values as some devices are known by different names in different regions. Note that if a list property only has one value for a particular device it will return an array with a single element.

For a full list of properties and values, see the Property Dictionary. List properties are denoted in the property dictionary with an 'L', for list. To access the property dictionary programatically see Accessing Metadata.

These properties can be used to influence the look of your webpage. The following snippet prints out the device screen dimensions only if the device is a mobile:

<?php

require_once 'path/to/core/51Degrees.php';
if ($_51d['IsMobile'] == 'True')
{
    // the device is a mobile. You could use mobile stylesheets.
    // print out the Height and Width of the screen.
    echo '<br />ScreenHeight: ' . $_51d['ScreenPixelsHeight'];
    echo '<br />ScreenWidth: ' . $_51d['ScreenPixelsWidth'];
}
?>

Particular list property values can be quickly searched for the in_array function:

<?php
if (in_array('audio/mp3', $_51d['CcppAccept']))
{
    // The browser accepts mp3 files.
}
?>

Note that ‘CcppAccept’ is a premium property. Go to Device Data for more information.

Need Help?

Using the Detector - Version 2

All the requesting device properties are stored in the variable $_51d which is populated simply by including the 51Degrees PHP Device Detector script:

<?php
include_once('path/to/51Degrees/51Degrees.mobi.php');
?>

Note that you may see 'include_once' or 'require_once'. They both make sure the given file is referenced only once, but require_once throws a fatal error if the file cannot be found. Include_once ignores the error.

$_51d is an associative array built for every requesting device. By using a 51Degrees property name as a key $_51d will return a string or an array of strings representing the relevant property value.

<?php
// get if the device is a mobile
$is_mobile = $_51d['IsMobile'];
// will be 'True' or 'False'

$hardware_name = $_51['HardwareName'][0];
// hardware name returns an array, 
// so use [0] to get first value
?>

HardwareName is what is known as a 'list' property. Some properties can have several values simultaneously that are all returned in an array. HardwareName may have several values as some devices are known by different names in different regions. Note that if a list property only has one value for a particular device it will return an array with a single element.

For a full list of properties and values, see the Property Dictionary. List properties are denoted in the property dictionary with an 'L', for list. To access the property dictionary programatically see Accessing Metadata.

These properties can be used to influence the look of your webpage. The following snippet prints out the device screen dimensions only if the device is a mobile:

<?php

require_once('path/to/51Degrees/51Degrees.mobi.php');
if($_51d['IsMobile'] == 'True')
{
    // the device is a mobile. You could use mobile stylesheets.
    // print out the Height and Width of the screen.
    echo '<br />ScreenHeight: ' . $_51d['ScreenPixelsHeight'];
    echo '<br />ScreenWidth: ' . $_51d['ScreenPixelsWidth'];
}
?>

Particular list property values can be quickly searched for the in_array function:

<?php
if(in_array('audio/mp3', $_51d['CcppAccept']))
{
    // The browser accepts mp3 files.
}
?>

Note that ‘CcppAccept’ is a premium property. Go to Device Data for more information.