dev-master
9999999-dev51Degrees composer package
MPL-2.0
The Development Requires
3.1.7
3.1.7.051Degrees composer package
MPL-2.0
The Development Requires
3.1.6
3.1.6.051Degrees composer package
MPL-2.0
The Development Requires
51Degrees composer package
Device Detection in Native PHP, (*1)
51Degrees for PHP can be installed by composer. Can be used like in basic examples., (*3)
Please note that the native PHP API is no longer actively developed. Instead please use the C-Extension or the Cloud Implementation., (*4)
Since native PHP is not capable of persistently storing data in memory the API is only capable of working in stream mode which relies on loading the bare minimum of the necessary headers and then using the data file on disk to perform detection. Normally in languages like Java and C# the headers would only be loaded once, upon the application start, and then reused for multiple detections However with native PHP this has to be done for every request which is slow and inefficient., (*5)
If you have root access to the server your website/service is running on consider using the C-Extension implementation., (*6)
If you are running in an environment with restricted access rights such as a WordPress blog on shared hosting then you should use the Cloud implementation., (*7)
This API is still maintained and is in the working order, but maintenance is only limited to bug fixes., (*8)
Also please note that the native PHP API requires files of version 3.1., (*9)
composer require pionix-labs/51degrees-php
basic-usage.php, (*10)
$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 "Mobile device.
"; } else { echo "Non-Mobile device.
"; }
match-metrics.php, (*11)
$fiftyOneDegrees = new PionixLabs\FiftyOneDegrees\DeviceDetection(); $fiftyOneDegrees->setDataFilePath(__DIR__ . '/../resources/tests/51Degrees-Lite.dat'); $_51d = $fiftyOneDegrees->getDeviceData(); // Match metrics: echo "DeviceId: " . $_51d["DeviceId"] . ", (*12)
"; echo "Method: " . $_51d["Method"] . ", (*13)
"; echo "Difference: " . $_51d["debug_info"]["difference"] . ", (*14)
";
To retrieve description for a particular property: metadata.php, (*15)
$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'];
To print all possible values for a chosen property: metadata-possible-values.php, (*16)
$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 ""; var_dump($_51d_meta_data['IsMobile']['Values']); echo "";
51Degrees for PHP allows for some global values to change its behaviour. If not set they will all use default options., (*17)
$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();
51Degrees composer package
MPL-2.0
51Degrees composer package
MPL-2.0
51Degrees composer package
MPL-2.0