Skip to content

rubricate/agent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rubricate UserAgent

Maintainer Source Code PHP from Packagist Latest Version Software License Total Downloads

Last Version

$ composer require rubricate/agent

Documentation is at https://rubricate.github.io/components/agent

Preparing the Configuration Data

<?php

$config = [
    'platforms' => [
        'windows nt 10.0' => 'Windows 10',
        'android'         => 'Android',
        'iphone'          => 'iPhone',
        'linux'   => 'Linux',
        'ubuntu'  => 'Ubuntu Linux',
        'fedora'  => 'Fedora Linux',
        'x11'     => 'Linux (Generic)'
    ],
    'browsers' => [
        'Chrome'  => 'Chrome',
        'Firefox' => 'Firefox',
        'MSIE'    => 'Internet Explorer',
    ],
    'mobiles' => [
        'iphone'   => 'Apple iPhone',
        'android'  => 'Android Device',
    ],
    'robots' => [
        'googlebot' => 'Googlebot',
    ]
];

Preparing the Configuration Data

<?php

use Rubricate\Agent\UserAgent;

// 1. Instantiate the class passing the configurations
$ua = new UserAgent($config);

// 2. Checking the device type
if ($ua->isMobile()) {
    echo "You are using a mobile device: " . $ua->getMobile();

} elseif ($ua->isRobot()) {
    echo "Hello, robot: " . $ua->getRobot();

} else {
    echo "You are on a Desktop.";
}

echo "<br>";

// 3. Obtaining specific browser information
if ($ua->isBrowser()) {
    echo "Browser: " . $ua->getBrowser() . " (Version: " . $ua->getVersion() . ")";
}

echo "<br>"; // 4. Checking the Platform (OS)
echo "Operating System: " . $ua->getPlatform();

echo "<br>";

/ 5. Accepted Languages
echo "Preferred Languages: " . implode(', ', $ua->getLanguages());

/ 6. Specific Boolean Check
if ($ua->acceptLang('pt-br')) {
    echo "The user accepts Brazilian Portuguese.";
}

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Identifies the platform, browser, robot, or mobile device of the browsing agent

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%