[PHP] PHP识别电脑、手机访问 →→→→→进入此内容的聊天室

来自 , 2020-09-22, 写在 PHP, 查看 158 次.
URL http://www.code666.cn/view/e93028bd
  1. <?php
  2. function isMobile(){
  3.         $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
  4.         $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
  5.         $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');
  6.         $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');
  7.         $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock)||CheckSubstrs($mobile_token_list,$useragent);
  8.         if($found_mobile){
  9.                 return true;
  10.         }else{
  11.                 return false;
  12.         }
  13. }
  14. function CheckSubstrs($substrs,$text){
  15.         foreach($substrs as $substr){
  16.                 if(false!==strpos($text,$substr)){
  17.                         return true;
  18.                 }
  19.                 return false;
  20.         }
  21. }
  22. if(isMobile()){
  23.         echo '手机登录 m.phpernote.com';
  24. }else{
  25.         echo '电脑登录 www.phpernote.com';
  26. }

回复 "PHP识别电脑、手机访问"

这儿你可以回复上面这条便签

captcha