1. 二宝博客首页
  2. php

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 '手机登录';else    echo '电脑登录';

]]>

原创文章,作者:键盘游走者,如若转载,请注明出处:https://www.708034.com/2015/08/php%e8%af%86%e5%88%ab%e7%94%b5%e8%84%91%e8%bf%98%e6%98%af%e6%89%8b%e6%9c%ba%e8%ae%bf%e9%97%ae%e7%bd%91%e7%ab%99/

发表评论

电子邮件地址不会被公开。 必填项已用*标注