正好需要,在网上找了好久,记录一下
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;
}
}
if (ismobile()){
header('location: ./app/index.php');//如果为手机端,执行跳转
}
else{
header('location: ./web/index.php');//如果非手机端,执行跳转
}
以上这篇php判断手机浏览还是web浏览,并执行相应的动作简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持硕编程。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!