PHP操作系统检测


PHP OS Detection

我试图找到一种简单的方法来显示依赖于操作系统的不同内容。具体来说,它有点像一个应用商店,为使用android设备的用户展示android应用程序,为windows用户展示windows应用程序,等等。

试试这个:

<?php
    // android
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
        header('Location: https://play.google.com/store/apps/details?id=YOUR_BUNDLE_ID');
        exit();
    }
    // ipad
    $isiPad = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
    // iphone/ipod
    if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
    {
        header('Location: https://itunes.apple.com/YOUR_LINKG_TO_APPLE_STORE');
        exit();
    }
    header('Location: http://www.default.com');
?>

你能做的就是使用51Degrees设备检测器。它是完美的移动设备检测,但也适用于桌面操作系统检测。

遵循51Degrees PHP入门中设置的4步。

识别操作系统:
$_51d['PlatformName']给出了操作系统的名称。
$_51d['PlatformVendor']给出了制造商(即Apple for OsX)
$_51d['PlatformVersion']给出检测到的操作系统版本。