您的位置:首页 > 移动开发

判断手机端还是pc端苹果系统出现的问题

2017-10-09 11:03 465 查看
情景描述:通常一个企业网站需要手机端和电脑端,这时就需要判断是手机浏览器还是电脑浏览器从而决定入口。

1,下面的这段代码就判断了是什么系统的浏览器

$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$is_pc = (strpos($agent, 'windows nt')) ? true : false;
$is_mac = (strpos($agent, 'mac os')) ? true : false;
$is_iphone = (strpos($agent, 'iphone')) ? true : false;
$is_android = (strpos($agent, 'android')) ? true : false;
$is_ipad = (strpos($agent, 'ipad')) ? true : false;


2,刚开始我是这样判断入口的

if($is_pc){
return Redirect::to('/we/index');
}elseif($is_mac){
return Redirect::to('/index/');
}elseif($is_iphone ){
return Redirect::to('/we/mobile');
}else{
return Redirect::to('/mobile/');
}


3,但随之出现问题,我苹果手机也进入了pc端的界面,后来打印$agent知道了苹果手机和苹果电脑都有含有man os ,苹果手机含有iphone而苹果电脑不含有,所以做如下调整即可

if($is_pc){
return Redirect::to('/we/index');
}elseif($is_iphone){
return Redirect::to('/mobile/');
}elseif($is_mac){
return Redirect::to('/we/index');
}else{
return Redirect::to('/mobile/');
}


觉得有用麻烦顶一下哦(* ̄︶ ̄)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: