稀酷客

 找回密码
 加入稀酷客

只需一步,快速开始

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1594|回复: 0

[特效源码] PHP判断是否为手机移动终端的函数代码

[复制链接]

339

主题

339

帖子

678

积分

高级会员

Rank: 4

积分
678
发表于 2018-5-4 10:02:43 | 显示全部楼层 |阅读模式
  1. function is_mobile_request(){   
  2.       $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';   
  3.       $mobile_browser = '0';   
  4.       if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))   
  5.         $mobile_browser++;   
  6.       if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))   
  7.         $mobile_browser++;   
  8.       if(isset($_SERVER['HTTP_X_WAP_PROFILE']))   
  9.         $mobile_browser++;   
  10.       if(isset($_SERVER['HTTP_PROFILE']))   
  11.         $mobile_browser++;   
  12.       $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));   
  13.       $mobile_agents = array(   
  14.             'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',   
  15.             'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',   
  16.             'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',   
  17.             'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',   
  18.             'newt','noki','oper','palm','pana','pant','phil','play','port','prox',   
  19.             'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',   
  20.             'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',   
  21.             'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',   
  22.             'wapr','webc','winw','winw','xda','xda-'   
  23.             );   
  24.       if(in_array($mobile_ua, $mobile_agents))   
  25.         $mobile_browser++;   
  26.       if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)   
  27.         $mobile_browser++;   
  28.       // Pre-final check to reset everything if the user is on Windows   
  29.       if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)   
  30.         $mobile_browser=0;   
  31.       // But WP7 is also Windows, with a slightly different characteristic   
  32.       if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)   
  33.         $mobile_browser++;   
  34.       if($mobile_browser>0)   
  35.         return true;   
  36.       else  
  37.         return false;   
  38. }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入稀酷客   

本版积分规则

QQ|Archiver|手机版|小黑屋|稀酷客 ( 冀ICP备14004526号-1 )

GMT+8, 2019-2-19 10:46 , Processed in 1.125007 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表