我在这里询问有关获取用户设备的脚本,即安卓或iOS或网络。我尝试过类似的东西,但在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;发布于 2016-03-19 19:36:31
正如我在评论中所说的,Android有一个linux内核,所以要再次找出操作系统是不是特别是Android,可以这样做:
$agent = $_SERVER["HTTP_USER_AGENT"];
//print_r($agent);
if (preg_match('/Linux/', $agent))
{
$os = 'Linux';
if (preg_match('/Android/', $agent))
{
$os = 'Android';
}
}
elseif (preg_match('/Windows/', $agent))
{
$os = 'Windows';
}
elseif (preg_match('/Mac/', $agent))
{
$os = 'Mac';
}
elseif (preg_match('/Apple/', $agent))
{
$os = 'Apple';
}
else
{
$os = 'UnKnown';
}
echo $os;它所做的是,当它得到(操作系统)是linux时,它还会检查操作系统是否也是android。
你所使用的是,每当它发现(OS)是linux时,它会将值linux放入$os中,并退出所有那些elseif包,所以它不能进入elseif (preg_match('/Windows/', $agent)) {...}。
希望能对你有所帮助!
https://stackoverflow.com/questions/36100993
复制相似问题