来源:未知 时间:2016-10-14 15:43 作者:xxadmin 阅读:次
[导读] PHP如何判断iPhone、iPad、Android及PC设备的方法。 原理是 $_SERVER[HTTP_USER_AGENT] 代码如下: ?php//获取USERAGENT$agent=strtolower($_SERVER[HTTP_USER_AGENT]);//分析数据$is_pc=(strpos($agent,windowsnt))?true:false;$is...
|
PHP如何判断iPhone、iPad、Android及PC设备的方法。 原理是$_SERVER['HTTP_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程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com