PHP code example of devicedetect / devicedetectionlib

1. Go to this page and download the library: Download devicedetect/devicedetectionlib 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/ */

    

devicedetect / devicedetectionlib example snippets




/**
  * Retrieve the User-Agent.
  * @method getUserAgent()
  * @return string|null The user agent if it's set.
 */

/**
  * Retrieve the list of known browsers.
  * @method getBrowsers()
  * @return array
 */

/**
  * Retrieve the list of operating systems.
  * @method getOperatingSystems()
  * @return array
 */

/**
  * Retrieve the list of device types.
  * @method getDeviceTypes()
  * @return array
 */

/**
  * Get device type.
  * @method getDeviceType($userAgent = null)
  * @param null $userAgent
  * @return string
 */

/**
  * Get device browser.
  * @method getBrowser()
  * @return string
 */

/**
  * Retrieve the User-Agent.
  * @method getOperatingSystem()
  * @return string
 */

/**
  * Mobile device detection.
  * @method isMobile($userAgent = null)
  * @param null $userAgent
  * @return bool
 */

/**
  * Tablet detection.
  * @method isTablet($userAgent = null)
  * @param null $userAgent
  * @return bool
 */

/**
  * Computer detection
  * @method isComputer($userAgent = null)
  * @param null $userAgent
  * @return bool
 */

/**
  * Ipad detection
  * @method isIpad()
  * @return bool
 */

/**
  * Iphone detection
  * @method isIphone()
  * @return bool
 */

/**
  * Android Os detection
  * @method isAndroid()
  * @return bool
 */

/**
  * Get version of os, browser etc
  * @method getVersion(string $key)
  * @param string $key
  * @return float|string
 */





namespace App\Http\Controllers;

use App\Device_Detect;

/**
 * Class DeviceDetectionController
 *
 * @package App\Http\Controllers
 */
class DeviceDetectionController extends Controller
{
    /**
     * @var Device_Detect
     */
    private $deviceDetect;

    /**
     * DeviceDetectionController constructor.
     *
     * @param $deviceDetect
     */
    public function __construct(Device_Detect $deviceDetect)
    {
        $this->deviceDetect = $deviceDetect;
    }
    
    /**
     * Device Detection
     */
    public function detect()
    {
        print_r($this->deviceDetect->getBrowser());
        echo "\n";
        print_r($this->deviceDetect->getOperatingSystem());
        echo "\n";
        print_r($this->deviceDetect->getDeviceType());
     }
}