PHP判断iPhone、iPad、Android及PC设备
2016-11-29 16:49
597 查看
原理是$_SERVER['HTTP_USER_AGENT']代码如下:
如果你只判断是否为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 //获取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判断iPhone、iPad、Android、PC设备
- PHP简单判断iPhone、iPad、Android及PC设备的方法
- 利用PHP判断iPhone、iPad、Android、PC设备
- PHP判断iPhone、iPad、Android、PC设备的方法
- PHP判断iPhone、iPad、Android、PC设备的方法
- PHP判断iPhone、iPad、Android、PC设备的方法
- JS判断设备终端(PC,iPad,iPhone,android)和浏览器(IE,Opera,Firefox,webKit)
- JS判断访问设备终端PC/iPad/iPhone/android 和浏览器IE/Opera/Firefox/webKit
- JS判断设备终端(PC,iPad,iPhone,android,winPhone)和浏览器
- js 判断是否为 Android IOS IPAD IPHONE 等移动设备访问
- javascript判断设备类型-手机(mobile)、安卓(android)、电脑(pc)、其他(ipad/iPod/Windows)等
- 判断访问浏览器客户端类型(pc,mac,ipad,iphone,android)
- 使用Javascript判断浏览器终端设备(PC、IOS(iphone)、Android)
- 判断用户设备是iPad还是iPhone的代码
- 判断用户设备是iPad还是iPhone的代码
- 如何将音视频发布到移动设备,android,ios,iphone,ipad等
- JS 判断浏览器客户端类型(ipad,iphone,android)
- iPad Android系统下,平板设备判断横竖屏,以及横竖屏变化之后的事件触发(html + javascript)
- JS判断客户端类型(ipad,iphone,android)
- JS 判断浏览器客户端类型(ipad,iphone,android)