Check out the latest documentation.

Usage - version 3.2

Function fiftyone_match()

Description

You can use the user agent HTTP header to get device properties by calling the fiftyone_match function.

Parameters

Function takes in a user agent string, typically derived from the PHP $_SERVER.

Returns

Function returns an array of property:value pairs for each of the properties available in your data file, or NULL if there was a problem.

Example:

											
											<?php
											
											
											$properties
											
											
											=
											
										 fiftyone_match(
											
											$_SERVER
											
										[
											
											'HTTP_USER_AGENT'
											
										]);

											
											?>
											
										

Function fiftyone_match_with_headers()

Description

Some browsers provide additional HTTP headers that can improve detection accuracy. You can now call a function that takes in a string of header : value pairs where the headers are separated by the new line. The API will automatically find the relevant HTTP headers and perform detection.

Parameters

Function takes in a string of HTTP header name : header value pairs where the header name is separated from the header value by a space or a colon. Entries must be separated by the new line '\n'.

Returns

Function returns an array of property:value pairs for each of the properties available in your data file, or NULL if there was a problem.

Example:

											
											<?php
											
											
											$headers
											
										;

											
											foreach
											
										 (
											
											$_SERVER
											
											
											as
											
											
											$key
											
											
											=>
											
											
											$value
											
										) {
  
											
											if
											
										 (
											
											strpos
											
										(
											
											$key
											
										, 
											
											"HTTP_"
											
										) 
											
											!==
											
											
											false
											
										) {
    
											
											$headers
											
											
											=
											
											
											$headers
											
											
											.
											
											
											$key
											
											
											.
											
											
											" "
											
											
											.
											
											
											$value
											
											
											.
											
											
											"
											
											
											\n
											
											
											"
											
										;
  }
}

											
											$result
											
											
											=
											
										 fiftyone_match_with_headers(
											
											$headers
											
										);

											
											?>
											
										

Function fiftyone_info()

Description

Displays information about the data file currently used by the device detection C extension module.

Parameters

No input required.

Returns

Prints a block of HTML with information about the data file used.

Example:

											
											<?php
											
										
fiftyone_info();

											
											?>
											
										

Usage - version 3.1

Device Properties

Device properties can be fetched with the fiftyone_degrees_get_properties function:

									$p = fiftyone_degrees_get_properties($_SERVER['HTTP_USER_AGENT']);
echo "Total properties in array: ".sizeof($p);
echo "<pre>";
var_dump($p);
echo "</pre>";

									

 

The function takes user agent string as a parameter and returns an array of properties and their values, like the $_51d variable in the pure PHP API. The above snippet produces the following result using the Lite data file:

Print screen of the result of executing the above php code.

Points to Note

The 51 Degrees data file needs to be refreshed on a regular basis in order to keep it current. This is best achieved by running a CRON job on the Linux server. Details of how to do this can be obtained here .  Additionally, a PHP script can be used to obtain meta data information. By default all property values are returned as strings.