PHP之判断是PC端还是移动端

PHP之判断是PC端还是移动端:

  1. public function isMobile(){
  2. $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
  3. $useragent_commentsblock = preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:'';
  4. function CheckSubstrs($substrs,$text){
  5. foreach($substrs as $substr)
  6. if(false!==strpos($text,$substr)){
  7. return true;
  8. }
  9. return false;
  10. }
  11. $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');
  12. $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');
  13. $found_mobile = CheckSubstrs($mobile_os_list,$useragent_commentsblock) || CheckSubstrs($mobile_token_list,$useragent);
  14. if ($found_mobile){
  15. return true;
  16. }else{
  17. return false;
  18. }
  19. }
  20. if (isMobile()){
  21. echo '手机登录';
  22. }else{
  23. echo '电脑登录';
  24. }
  25. ?>
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/956
0 评论
2.3k

发表评论

!