PHP code example of bleuren / agent

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

    

bleuren / agent example snippets


$isDesktop = Agent::isDesktop();
$isMobile = Agent::isMobile();
$isTablet = Agent::isTablet();

$browser = Agent::browser();
$platform = Agent::platform();

// Check if the current user agent is a robot.
$isRobot = Agent::isRobot();

// Alternatively, the same result can be achieved with isCrawler()
$isCrawler = Agent::isCrawler();

// You can also check for a specific crawler by passing a user agent string.
$isSpecificCrawler = Agent::isCrawler('specific-user-agent-string');

// Retrieve the name of the detected robot/crawler, if any.
$robot = Agent::robot();

Agent::setHttpHeaders(['User-Agent' => $_SERVER['HTTP_USER_AGENT']]);
$httpHeaders = Agent::getHttpHeaders();
$mobileHeaders = Agent::getMobileHeaders();
$cloudFrontHeaders = Agent::getCloudFrontHttpHeaders();

Agent::setUserAgent('specific-user-agent-string');
$userAgent = Agent::getUserAgent();

// Determine the device type: 'desktop', 'mobile', 'tablet', or 'robot'.
$deviceType = Agent::deviceType();

// Browser and platform detection
$browser = Agent::browser();
$platform = Agent::platform();

// Detailed robot detection
if (Agent::isRobot()) {
    $robot = Agent::robot();
}