欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php判断手机访问还是电脑访问示例分享

程序员文章站 2022-06-14 12:14:21
复制代码 代码如下:

复制代码 代码如下:

<?php
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())
 echo '手机登录m.jb51.com';
else
 echo '电脑登录www.jb51.com';
?>