phpmk / devicedata
PHP.mk PHP Library for using Device API service
v3
2020-11-12 14:49 UTC
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
README
With this library, you can very easily detect device details. Especially for mobile and tablet.
Composer installation
composer require phpmk/devicedata:v1
Configuration:
./config/config-sample.php
<?php//rename file to config.php $config['token'] = '[your PHP.mk token]'; //You can get free token on https://php.mk/services/device
?>
How to use:
./examples/simple.php
<?phprequire_once '../config/config.php'; require_once '../src/DeviceDetails.php'; $device = new DeviceDetails($config['token']); $deviceData = $device->getDevice(); if ($device->errors()) { print_r($device->errors()); } else { print_r($deviceData); }
?>
./examples/advanced.php
<?phprequire_once '../config/config.php'; require_once '../src/DeviceDetails.php'; $device = new DeviceDetails($config['token']); $device->setUserAgent('Mozilla/5.0 (Linux; Android 4.4.2; GT-P5210 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.109 Safari/537.36'); $deviceData = $device->getDevice(); if ($device->errors()) { print_r($device->errors()); } else { print_r($deviceData); }
?>
Public methods:
DeviceDetails :: __construct/** * Initialize class object * * @param array $token Token for web service * * @return object|null Return instance of the class or null if missing token /DeviceDetails :: setUserAgent
/ * Manually set UserAgent * * @param string $userAgent Browser UserAgent * * @return void /DeviceDetails :: getDevice
/ * Get Device data * * @return mixed Return everything about device /DeviceDetails :: errors
/ * Get errors from service * * @return array Return service errors **/