整理的一段php判断iPhone、iPad、Android、PC设备的例子. 我将使用Windows系统的设备定为PC,毕竟博客面向中国用户,大部分家用设备还是用的Windows系统. 原理是判断浏览器提交的USER AGENT,代码如下:
<?php
//获取USER AGENT
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
//分析数据
$is_pc = (strpos($agent, 'windows nt')) ? true : false;
$is_iphone = (strpos($agent, 'iphone')) ? true : false;
$is_ipad = (strpos($agent, 'ipad')) ? true : false;
$is_android = (strpos($agent, 'android')) ? true : false;
//输出数据
if($is_pc){
echo "这是PC";
}
if($is_iphone){
echo "这是iPhone";
}
if($is_ipad){
echo "这是iPad";
}
if($is_android){
echo "这是Android";
}
?>
如果你只判断是否为iphone设备可以如下来进行操作,代码如下:
<?php 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;
} ?>
(责任编辑:最模板) |

仿taonpost代购网站系统整站
人气:902
汽车商城网店程序源码|
人气:1048
shopex绿色类凡客模板
人气:546
英文ecshop假发类外贸商城
人气:1570
时尚起义ecshop模板|衣服模
人气:603
ecshop免费仿娜拉化妆品购
人气:5749