例如:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
1、识别是否为手机客户端的只要识别User-Agent中是否有"Mobile"字段即可
2、系统识别
目前主流的系统标识对应如下:
"Windows NT 6.4":"Windows 10",
"Windows NT 6.3":"Windows 8.1",
"Windows NT 6.2":"Windows 8",
"Windows NT 6.0":"Windows vista",
"Windows NT 6.1":"Windows 7",
"Windows NT 5.1":"Windows XP",
function getClientSystemType($userAgent)
{
$arr = [
"Windows NT 6.4" => "Windows 10",
"Windows NT 6.3" => "Windows 8.1",
"Windows NT 6.2" => "Windows 8",
"Windows NT 6.0" => "Windows vista",
"Windows NT 6.1" => "Windows 7",
"Windows NT 5.1" => "Windows XP",
];
foreach ($arr as $k => $v) {
if (str_contains($userAgent, $k)) {
return $v;
}
}
return 'unknown';
}
3、浏览器
"SogouMobileBrowser":"搜狗手机浏览器",
"UCBrowser":"UC浏览器",
"UCWEB":"UC浏览器",
"Opera":"Opera浏览器",
"QQBrowser":"QQ浏览器",
"TencentTraveler":"QQ浏览器",
"MetaSr":"搜狗浏览器",
"360SE":"360浏览器",
"The world":"世界之窗浏览器",
"Maxthon":"遨游浏览器",
'Chrome':"谷歌浏览器",
function getClientBrowserType($userAgent)
{
$arr = [
"SogouMobileBrowser" => "搜狗手机浏览器",
"UCBrowser" => "UC浏览器",
"UCWEB" => "UC浏览器",
"Opera" => "Opera浏览器",
"QQBrowser" => "QQ浏览器",
"TencentTraveler" => "QQ浏览器",
"MetaSr" => "搜狗浏览器",
"360SE" => "360浏览器",
"The world" => "世界之窗浏览器",
"Maxthon" => "遨游浏览器",
'Chrome' => "谷歌浏览器",
];
foreach ($arr as $k => $v) {
if (str_contains($userAgent, $k)) {
return $v;
}
}
return 'unknown';
}