thinkphp首页判断是移动端登陆还是手机端登陆
2014-12-24 10:24
246 查看
class XXXX extends XXX {
public function index(){
if($this->isMobile()){
//手机访问
$this->display('mobile');
}else{
//pc端访问
$this->display('pc');
}
}
public function isMobile(){
$useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
function CheckSubstrs($substrs,$text){
foreach($substrs as $substr)
if(false!==strpos($text,$substr)){
return true;
}
return false;
}
$mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
CheckSubstrs($mobile_token_list,$useragent);
if ($found_mobile){
return true;
}else{
return false;
}
}
}
public function index(){
if($this->isMobile()){
//手机访问
$this->display('mobile');
}else{
//pc端访问
$this->display('pc');
}
}
public function isMobile(){
$useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
function CheckSubstrs($substrs,$text){
foreach($substrs as $substr)
if(false!==strpos($text,$substr)){
return true;
}
return false;
}
$mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
$mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');
$found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||
CheckSubstrs($mobile_token_list,$useragent);
if ($found_mobile){
return true;
}else{
return false;
}
}
}
相关文章推荐
- thinkphp3.2判断是否为手机端,还是电脑端,跳转到相应页面
- ThinkPHP中判断是手机端还是电脑端访问的方法
- 【移动端】判断PC端还是手机端
- ThinkPHP中判断是手机端还是电脑端访问的方法
- 手机端左右全屏滑动(加精)【判断PC还是移动端】
- js判断用户的浏览器设备是移动端还是pc端
- PHP判断访问者手机移动端还是PC端的函数,亲测好用
- PHP判断PC端还是手机端
- uaredirect.js 进行判断是pc还是wap端(移动端) wap端跳转页面
- js判断手机端Android手机还是iPhone手机
- 判断客户端是手机端还是PC端
- JAVA判断移动端还是PC端访问
- JAVA-判断请求来自PC端还是手机端
- PHP判断用户使用手机端登录还是pc端登录(企业版)
- thinkphp判断是否为手机登陆的方法
- 判断当前浏览器是移动端还是pc端
- 移动端判断是否处于横屏还是竖屏状态
- 简单的利用JS来判断页面是在手机端还是在PC端打开的方法
- js如何判断用户是在PC端和还是移动端访问
- java判断是移动端还是pc端