2

我正在尝试在 PHP(Codeingiter) 中获取访问者的操作系统。我试过https://github.com/serbanghita/Mobile-Detect。它有 70% 的时间对我有用。但它仍然无法准确检测。大量 Android 流量未被检测为移动设备或平板电脑。

4

3 回答 3

3

没有准确的方法可以通过 php 或任何其他服务器语言检测操作系统。

这种检测通常依赖于浏览器代理,但它可以被伪造并且大多数时候没有足够的信息。

于 2017-06-02T06:17:23.933 回答
1

您必须为其他设备(如 iPad 和我错过的其他设备)添加检查...

$hua = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
$os = 'I have no idea...';

if(preg_match('/android/i', $hua)) {
    $os = 'Android';
} elseif (preg_match('/linux/i', $hua)) {
    $os = 'Linux';
} elseif (preg_match('/iphone/i', $hua)) {
    $os = 'iPhone';
} elseif (preg_match('/macintosh|mac os x/i', $hua)) {
    $os = 'Mac';
} elseif (preg_match('/windows|win32/i', $hua)) {
    $os = 'Windows';
}
echo $os;
于 2017-06-02T06:49:42.210 回答
0

CodeIgniter 中的用户代理类库提供了执行任务的功能。您可以在此处找到有关它们的更多详细信息: 用户代理类库

专门寻找 platform() 函数来检测访问者的操作系统。

于 2017-06-02T18:29:25.877 回答