这是一个客户端设备类型的函数,不过使用的还是浏览器代理的概念,没有很多的改变,只不过他注重的是判断是
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 '客户端设备类型为安卓手机或安卓平板电脑';
}
?>