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 '电脑登录';
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,062评论 0 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,131评论 19 139
  • 外貌协会的我,不知从何时起,欣赏男人的五官时,着重看鼻子,然而,这一内心倾向越来越坚定,促使我认定这条铁打的事实。...
    八月初五阅读 16,215评论 11 11
  • 逗逗是个92年的男生,朴实,黑皮肤,小眼睛,脸上有痘痘,标准分前后鼻音的普通话,一听就知道不是南方人。看起来很实在...
    修道士的袍阅读 313评论 0 2