【发布时间】:2016-07-06 04:31:12
【问题描述】:
我在这里询问有关获取用户设备(即 Android、iOS 或 Web)的脚本。 我尝试过类似但在 android 手机中显示 Linux。
$agent = $_SERVER["HTTP_USER_AGENT"];
//print_r($agent);
if (preg_match('/Linux/', $agent))
$os = 'Linux';
elseif (preg_match('/Windows/', $agent))
$os = 'Windows';
elseif (preg_match('/Mac/', $agent))
$os = 'Mac';
elseif (preg_match('/Android/', $agent))
$os = 'Android';
elseif (preg_match('/Apple/', $agent))
$os = 'Apple';
else
$os = 'UnKnown';
echo $os;
【问题讨论】:
-
因为安卓有linux内核,所以应该显示
Linux。 -
只需更改
ifs 的顺序:首先检查更具体的值(例如“Android”),然后检查“Linux”。