PHP建设的网站判断手机访问还是电脑访问如何写?下面煜阳网站制作人员为您详细介绍下。
PHP建设的网站判断手机访问还是电脑访问的函数如下:
function isMobile(){
$userAgent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$userAgent_CommentsBlock=preg_match('|.∗?.∗?|',$userAgent,$matches)>0?$matches[0]:'';
function Check_subset($subsets,$text){
foreach($subsets as $subset)
if(false!==strpos($text,$subset)){
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','PocketP>C','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())
echo '手机登录';
else
echo '电脑登录';
PHP建设的网站判断手机访问还是电脑访问的代码就写到这里了,亲们可以试试,我公司网站建设制作人员亲测的,没有问题哦。