PHP code example of foroco / php-browser-detection
1. Go to this page and download the library: Download foroco/php-browser-detection 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/ */
foroco / php-browser-detection example snippets
you use PHP in Windows OS use another path style:
//
$Browser = new foroco\BrowserDetection();
$useragent = $_SERVER['HTTP_USER_AGENT'];
// Get all possible environment data (array):
$result = $Browser->getAll($useragent);
// Get OS data (array):
$result = $Browser->getOS($useragent);
// Get Browser data (array):
$result = $Browser->getBrowser($useragent);
// Get Device type data (array):
$result = $Browser->getDevice($useragent);
/*
Also methods may returned result as JSON string
Just use second argument of methods as 'JSON'
*/
// Get all possible environment data (JSON):
$result = $Browser->getAll($useragent, 'JSON');
print_r($result);
// ... etc
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.4150.0 Iron Safari/537.36';
$result = $Browser->getAll($useragent);
print_r($result);
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (Linux; arm_64; Android 14; SM-G965F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.6613.99 YaBrowser/24.7.4.147 Mobile Safari/537.36';
$result = $Browser->getOS($useragent);
print_r($result);
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/128.0.6613.98 Mobile/15E148 Safari/604.1';
$result = $Browser->getBrowser($useragent);
print_r($result);
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (SMART-TV; Linux; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/2.2 Chrome/63.0.3239.84 TV Safari/537.36';
$result = $Browser->getDevice($useragent);
print_r($result);
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36';
$Browser->setTouchSupport(); // Call if Touch events detected in browser by JavaScript code ('ontouchstart' in window)
$result = $Browser->getAll($useragent);
print_r($result);
$Browser = new foroco\BrowserDetection();
$useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36';
$result = $Browser->getAll($useragent, 'JSON');
print_r($result);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.