PHP 判断手机访问函数

function is_mobile_request()   {     $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';        if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))     {      return true;  }  if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false)) {    return true;  }     if(isset($_SERVER['HTTP_X_WAP_PROFILE']))    {      return true;  }    if(isset($_SERVER['HTTP_PROFILE']))     {      return true;  }  $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))     {      return true;  }      if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)     {      return true;  }  if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)  {  return true;  }  return false;}

]]>

原创文章,作者:键盘游走者,如若转载,请注明出处:http://www.708034.com/2017/04/php-%e5%88%a4%e6%96%ad%e6%89%8b%e6%9c%ba%e8%ae%bf%e9%97%ae%e5%87%bd%e6%95%b0/

发表评论

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