无限星辰工作室-客户无限互联网动力之源

标题: 网站手机版判断代码 [打印本页]

作者: crx349    时间: 2015-11-1 23:32
标题: 网站手机版判断代码
  1. <?php

  2. is_mobile_request();

  3. function is_mobile_request()  
  4. {  
  5.   $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';  
  6.   $mobile_browser = '0';  
  7.   if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))  
  8.     $mobile_browser++;  
  9.   if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))  
  10.     $mobile_browser++;  
  11.   if(isset($_SERVER['HTTP_X_WAP_PROFILE']))  
  12.     $mobile_browser++;  
  13.   if(isset($_SERVER['HTTP_PROFILE']))  
  14.     $mobile_browser++;  
  15.   $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));  
  16.   $mobile_agents = array(  
  17.         'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',  
  18.         'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',  
  19.         'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',  
  20.         'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',  
  21.         'newt','noki','oper','palm','pana','pant','phil','play','port','prox',  
  22.         'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',  
  23.         'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',  
  24.         'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',  
  25.         'wapr','webc','winw','winw','xda','xda-'
  26.         );  
  27.   if(in_array($mobile_ua, $mobile_agents))  
  28.     $mobile_browser++;  
  29.   if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)  
  30.     $mobile_browser++;  
  31.   // Pre-final check to reset everything if the user is on Windows  
  32.   if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)  
  33.     $mobile_browser=0;  
  34.   // But WP7 is also Windows, with a slightly different characteristic  
  35.   if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)  
  36.     $mobile_browser++;  
  37.   if($mobile_browser>0) {
  38. //跳转到手机版
  39.         header('Location: http://www.xmspace.net/index.php');
  40.         exit;
  41.   }else{
  42. //默认电脑版
  43.     header('Location: http://www.xmspace.net/index.php');
  44.         exit;  
  45.   }
  46. }


  47. ?>
复制代码







欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://xmspace.net/) Powered by Discuz! X3.4