PHP简单判断iPhone、iPad、Android及PC设备的方法
网络编程 2021-07-05 08:23www.168986.cn编程入门
这篇文章主要介绍了PHP简单判断iPhone、iPad、Android及PC设备的方法,可有效的判断出移动设备与PC端类型,需要的朋友可以参考下
本文实例讲述了PHP简单判断iPhone、iPad、Android及PC设备的方法。分享给大家供大家参考,具体如下:
因为工作需要我们需要知道是什么样了用户访问了我网站了,现在的移动设备种类多了,狼蚁网站SEO优化我们一起来看长沙网络推广整理的一段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设备可以如下来进行操作,代码如下:
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相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程