PHP code example of cnwyt / user-agent-parser
1. Go to this page and download the library: Download cnwyt/user-agent-parser 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/ */
cnwyt / user-agent-parser example snippets
use Cnwyt\UserAgentParser\UserAgentParser;
// 获取 UserAgent
// $ua = $request->get('ua');
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0';
// 实例化 UserAgentParser
$agent = (new UserAgentParser());
// 设置 UserAgent
$agent->setUserAgent($ua);
// 获取解析结果
$device = $agent->getDeviceName();
$browerName = $agent->getBrowserName();
$browerVersion = $agent->getBrowserVersion();
$systemName = $agent->getSystemName();
$systemVersion = $agent->getSystemVersion();
// 检测
$isIos = $agent->isIOS();
$isAndroid = $agent->isAndroidOS();
$isWechat = $agent->isWechatBrowser();