top

PHP获取客户端机型,可区分windows、ios、android

将下面代码放到公共方法function.php里面

/*********获取客户端来源的类型******/
function get_device_type()
{
//全部变成小写字母
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$type = 'other';
//分别进行判断
if(strpos($agent, 'windows '))
{
$type = 'windows';
}
if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
{
$type = 'ios';
}
if(strpos($agent, 'android'))
{
$type = 'android';
}
return $type;
}
/*********获取客户端来源的类型******/ function get_device_type() { //全部变成小写字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; //分别进行判断 if(strpos($agent, 'windows ')) { $type = 'windows'; } if(strpos($agent, 'iphone') || strpos($agent, 'ipad')) { $type = 'ios'; } if(strpos($agent, 'android')) { $type = 'android'; } return $type; }
/*********获取客户端来源的类型******/
function get_device_type()

{
     
    //全部变成小写字母

    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);


    $type = 'other';

    //分别进行判断
    if(strpos($agent, 'windows '))

    {

        $type = 'windows';

    }

    if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))

    {

        $type = 'ios';

    }

    if(strpos($agent, 'android'))

    {
        $type = 'android';
    }
    return $type;
}

需要用到的地方调用即可

$type_device=get_device_type();
照片压缩项目里面有对应的方法,经测试可以拿到正确的机型

THE END
icon
0
icon
打赏
icon
分享
icon
二维码
icon
海报