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 '电脑登录';
网友评论