PHP code example of pionix-labs / 51degrees-php

1. Go to this page and download the library: Download pionix-labs/51degrees-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pionix-labs / 51degrees-php example snippets


$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d = $fiftyOneDegrees->getDeviceData();

// Detection results are stored in the $_51d global.
$isMobile = $_51d['IsMobile'];

// Use like:
if ($isMobile) {
    echo "<h3>Mobile device.</h3>";
} else {
    echo "<h3>Non-Mobile device.</h3>";
}

$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d = $fiftyOneDegrees->getDeviceData();

// Match metrics:
echo "<p>DeviceId: " . $_51d["DeviceId"] . "</p>";
echo "<p>Method: " . $_51d["Method"] . "</p>";
echo "<p>Difference: " . $_51d["debug_info"]["difference"] . "</p>";

$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d_meta_data = $fiftyOneDegrees->getMetadata();

// $_51d_meta_data global contains metadata for properties and values.
// Print description for the IsMobile property.
echo $_51d_meta_data['IsMobile']['Description'];

$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
$_51d_meta_data = $fiftyOneDegrees->getMetadata();

// Shows all possible valus for the IsMobile property and a
// description for each value.
echo "<pre>";
var_dump($_51d_meta_data['IsMobile']['Values']);
echo "</pre>";

$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection();
$fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat');
/**
 * Controls if property values are set to their typed values or strings.
 * Defaults to TRUE, set to FALSE to disable.
 */
$fiftyOneDegrees->setReturnStrings(true);
// NOTE: Much of the metadata for this property has not been set,
// so you may see strings for things which should not be strings. }

/**
 * Controls which property values should be returned from detection. 
 * Greater performance can be gained from a restricted list of properties.
 * By default all values are returned.
 */
 $fiftyOneDegrees->setProperties(['IsMobile', 'HardwareModel', 'PlatformName', 'BrowserName']);
 $_51d = $fiftyOneDegrees->getDeviceData();

composer