PHP code example of eprofos / user-agent-analyzer

1. Go to this page and download the library: Download eprofos/user-agent-analyzer 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/ */

    

eprofos / user-agent-analyzer example snippets


return [
    // ...
    Eprofos\UserAgentAnalyzerBundle\EprofosUserAgentAnalyzerBundle::class => ['all' => true],
];

use Eprofos\UserAgentAnalyzerBundle\Service\UserAgentAnalyzer;

class YourController
{
    public function someAction(UserAgentAnalyzer $analyzer)
    {
        $result = $analyzer->analyzeCurrentRequest();
        
        // Access the results
        $osName = $result->getOsName();           // e.g., "Windows"
        $osVersion = $result->getOsVersion();     // e.g., 10.0
        $browserName = $result->getBrowserName(); // e.g., "Chrome"
        $deviceType = $result->getDeviceType();   // e.g., "desktop"
        
        // Check device type
        $isMobile = $result->isMobile();    // true if device is mobile
        $isDesktop = $result->isDesktop();  // true if device is desktop
        $isTablet = $result->isTablet();    // true if device is tablet
        
        // Get all information as array
        $allInfo = $result->toArray();
    }
}

use Eprofos\UserAgentAnalyzerBundle\Service\UserAgentAnalyzer;

class YourController
{
    public function someAction(
        UserAgentAnalyzer $analyzer,
        Request $request
    ) {
    {
        // Analyze current request with touch support detection
        $result = $analyzer->analyzeCurrentRequest(true);

        // Or analyze specific user agent with touch support
        $userAgent = $request->headers->get('User-Agent');
        $result = $analyzer->analyze($userAgent, true);

        // Check for specific browser features
        $isWebView = $result->isBrowserAndroidWebview() || $result->isBrowserIosWebview();
        $isDesktopMode = $result->isBrowserDesktopMode();
        $is64Bit = $result->is64BitsMode();
    }
}