PHP code example of soumen-dey / laravel-user-agent

1. Go to this page and download the library: Download soumen-dey/laravel-user-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/ */

    

soumen-dey / laravel-user-agent example snippets


'providers' => [
    // ...
    Soumen\Agent\AgentServiceProvider::class,
];

'aliases' => [
	//...
    'Agent' => Soumen\Agent\Facades\Agent::class,
];

use Soumen\Agent\Agent;

// or

use Soumen\Agent\Facades\Agent

Agent::browser(); // returns all the details related to the visitor's browser

Agent::ip(); // the ip address of the visitor
Agent::device(); // details related to the visitor's device, eg, Phone, Tablet, etc.
Agent::header(); // details related to the request's header
Agent::platform(); // details related to the platform of the visitor, eg. Windows, etc.
Agent::userAgent(); // returns the HTTP_USER_AGENT string

Agent::server(); // returns details related to the server

Agent::browser('name'); // Firefox 61
Agent::browser()->name; // Firefox 61
Agent::browser()->getName(); // Firefox 61

$browser = Agent::get('browser'); // returns the browser service
$browser = Agent::browser(); // same as above

use Soumen\Agent\Services\Browser;

Browser::get(); // returns all details related to the visitor's browser
Browser::getDetails(); // same as get() method

use Soumen\Agnet\Services\Device;
use Soumen\Agent\Services\Platform;

$device = Device::get(); // get details about the visitor's device
$platform = Platform::get(); // get details related to the visitor's platform

use Soumen\Agent\Services\Browser;

// get the name of the browser
$browser = Browser::get('name');
$browser = Browser::get()->name;
$browser = Browser::get()->name();
$browser = Browser::get()->getName();

// or

$browser = Browser::getDetails('name');
$browser = Browser::getDetails()->name;
...
// You get the idea

Agent::browser('name'); // Firefox 61
Agent::platform('name'); // Windows 10

Agent::browser()->name;
Agent::platform()->name;

use Soumen\Agent\Services\Browser;
use Soumen\Agent\Services\Platform;

Browser::get('name'); // Firefox 61
Platform::get('name'); // Windows 10

// or

Browser::getDetails('name'); // Firefox 61
Platform::getDetails('name'); // Windows 10

$browser = Agent::browser();

use Soumen\Agent\Services\Browser;

$browser = Browser::get();

// or

$browser = Browser::getDetails();

$platform = Agent::platform();

use Soumen\Agent\Services\Platform;

$platform = Platform::get();

// or

$platform = Platform::getDetails();

$device = Agent::device();

use Soumen\Agent\Services\Device;

$device = Device::get();

// or

$device = Device::getDetails();

$userAgent = Agent::userAgent();

use Soumen\Agent\Services\UserAgent;

$userAgent = UserAgent::get();

$header = Agent::header();

use Soumen\Agent\Service\Header;

$header = Header::get();

// or

$header = Header::getDetails();

Header::get('user-agent');
Agent::header('user-agent');

$server = Agent::server();

use Soumen\Agent\Services\Server;

$server = Server::get();

// or

$server = Server::getDetails();