PHP OS检测

时间:2014-03-11 09:59:06

标签: php android ios operating-system device

我正在尝试找到一种简单的方法来显示依赖于操作系统的不同内容。把它放到上下文中,它有点像一个应用程序商店,它将为使用Android设备和windows用户的人们等显示Android应用程序。

2 个答案:

答案 0 :(得分:0)

试试这个:

<?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');
?>

答案 1 :(得分:0)

您可以使用51Degrees设备检测器。它非常适合移动设备检测,但在桌面操作系统检测方面也很有效。

按照51Degrees PHP Getting Started上的4步设置。

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