logo
当前位置:首 页 > 编程技术 >后端开发 >PHP语言 > 查看文章

这是一个客户端设备类型的函数,不过使用的还是浏览器代理的概念,没有很多的改变,只不过他注重的是判断是

iPhone还是iPad。这个比较专一,然后在判断是否是安装设备,安装设备就不区分平板和手机了。不过如果需要可以再细分下的;

 

//获取客户端设备的类型 by Ken http://ken.01h.net/1020.html
function get_device_type(){
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$type = 'other';
if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){
$type = 'ios';
}
if(strpos($agent, 'android')){
$type = 'android';
}
return $type;
}
 
//示例
if(get_device_type()=='ios'){
echo '客户端设备类型为iPhone或iPad';
}
if(get_device_type()=='android'){
echo '客户端设备类型为安卓手机或安卓平板电脑';
}
?>
说说梦想,谈谈感悟 ,聊聊技术,有啥要说的来github留言吧 https://github.com/cjx2328

—— 陈 建鑫

陈建鑫
你可能也喜欢Related Posts
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容。站长联系:cjx2328#126.com(修改#为@)
Copyright ©ziao Studio All Rights Reserved. E-mail:cjx2328#126.com(#号改成@) 沪ICP备14052271号-3