PHP验证终端类型是否为手机的简单实例

作者:袖梨 2022-06-24
代码如下 复制代码

/**

* 判断当前访问的用户是 PC端 还是 手机端 返回true 为手机端 false 为PC 端

* @return boolean

*/

functionisMobile(){

$useragent=isset($_SERVER['HTTP_USER_AGENT']) ?$_SERVER['HTTP_USER_AGENT'] :'';

//echo $useragent;die;

$useragent_commentsblock=preg_match('|(.*?)|',$useragent,$matches)>0?$matches[0]:'';

functionCheckSubstrs($substrs,$text){

foreach($substrsas$substr)

if(false!==strpos($text,$substr)){

returntrue;

}

returnfalse;

}

$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){

returntrue;

}else{

returnfalse;

}

}

相关文章

精彩推荐