实例1:主要是要用到http_user_agent,它表示的意思是用来检查浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好的代码。
监测代码如下:
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;}
通过调用objective-c这个函数,就能获取到手机的类型。
实例2:只需要一个判断就好
<?phpif(strpos($_server['http_user_agent'], 'iphone')||strpos($_server['http_user_agent'], 'ipad')){ echo 'systerm is ios';}else if(strpos($_server['http_user_agent'], 'android')){ echo 'systerm is android';}else{ echo 'systerm is other';}?>
实例3:这个实例可能有些偏题不过也分享给大家
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;}
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php微信自动获取收货地址api用法实例详解
php判断用户是否已经登录实例分析
php实现微信公众号自定义分享内容的方法
以上就是php判断手机是ios还是android的三个方法的详细内容。
