源码论坛,商业源码下载,尽在锦尚中国商业源码论坛

标题: php判断手机端跳转域名的代码 [打印本页]

作者: 欧阳锋    时间: 2020-6-6 22:08
标题: php判断手机端跳转域名的代码
最全的一个php判断手机端跳转域名的代码!

我自己编写项目的时候经常用到,分享给大家!!

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


使用方法:把http://m.52jscn.com域名改为你的手机端域名,直接将代码放到首页的php文件中






欢迎光临 源码论坛,商业源码下载,尽在锦尚中国商业源码论坛 (https://bbs.52jscn.com/) Powered by Discuz! X3.3