php判断是否移动设备
php判断是否移动手机设备函数,php判断手机访问函数.
相对精准的判断方式:
- function is_Mobile_Device(){
- //获取ALL_HTTP全部的http信息
- $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
- $mobile_browser = '0';
- if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
- $mobile_browser++;
- if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
- $mobile_browser++;
- if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
- $mobile_browser++;
- if(isset($_SERVER['HTTP_PROFILE']))
- $mobile_browser++;
- $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
- $mobile_agents = array(
- 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
- 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
- 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
- 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
- 'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
- 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
- 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
- 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
- 'wapr','webc','winw','winw','xda','xda-'
- );
- if(in_array($mobile_ua, $mobile_agents))
- $mobile_browser++;
- if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
- $mobile_browser++;
- if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
- $mobile_browser=0;
- if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
- $mobile_browser++;
- if($mobile_browser>0)
- return true;
- else
- return false;
- }
简单通过user-agent方式判断
- function isMobileDevice() {
- if(isset($_SERVER['HTTP_USER_AGENT'])) { //判断获取客户端标识
- $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
- $clientkeywords = array(
- 'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-'
- ,'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
- 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini',
- 'operamobi', 'opera mobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile'
- );
- // 从获取的HTTP_USER_AGENT中查找手机浏览器关键字进行判断
- if(preg_match("/(".implode('|',$clientkeywords).")/i",$userAgent)&&strpos($userAgent,'ipad') === false)
- {
- return true;
- }
- }
- return false;
- }
本文作者:未来往事
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
此处评论已关闭