PHP获取设备类型

  public static function getDevice()
    {
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
        {
            return 'mobile';
        }
        if (isset($_SERVER['HTTP_USER_AGENT']))
        {
            $clientKEY = array ('nokia','sony','ericsson','mot','samsung','htc','huawei','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iPhone','phone','ipod','ipad','blackberry','meizu','Android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile');
            if (preg_match("/(" . implode('|', $clientKEY) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
            {
                return 'mobile';
            }
        }
        if (isset($_SERVER['HTTP_ACCEPT']))
        {
            if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
            {
                return 'mobile';
            }
        }
        return 'pc';
    }

你可能感兴趣的:(PHP获取设备类型)