Home  >  Article  >  Backend Development  >  What is the php mobile phone jump code?

What is the php mobile phone jump code?

藏色散人
藏色散人Original
2020-10-10 10:22:182088browse

php mobile phone jump code is [function wappc($ac='towap'){$is_wap=checkmobile();if($is_wap){ if($_SERVER['HTTP_HOST']==.. .】.

What is the php mobile phone jump code?

Recommendation: "PHP Video Tutorial"

php realizes automatic jump of mobile site

php realizes the automatic jump of the mobile site, which means that when you use your mobile phone to access the PC site, it will automatically jump to the corresponding wap site.

To realize this function, we have to take three steps.

The first step is to determine whether the accessed terminal is a mobile phone. The code is as follows

/** *  * 根据php的$_SERVER['HTTP_USER_AGENT'] 中各种浏览器访问时所包含各个浏览器特定的字符串来判断是属于PC还是移动端 *移动端,返回true*程序员人生 wfuyu.com 2016-0317 */function checkmobile() { global $_G; $mobile = array();//各个触控浏览器中$_SERVER['HTTP_USER_AGENT']所包含的字符串数组 static $touchbrowser_list =array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini',    'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung',    'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser',    'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource',    'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone',    'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop',    'benq', 'haier', '^lct', '320x320', '240x320', '176x220');//window手机浏览器数组【猜的】 static $mobilebrowser_list =array('windows phone');//wap浏览器中$_SERVER['HTTP_USER_AGENT']所包含的字符串数组 static $wmlbrowser_list = array('cect', 'compal', 'ctl', 'lg', 'nec', 'tcl', 'alcatel', 'ericsson', 'bird', 'daxian', 'dbtel', 'eastcom',   'pantech', 'dopod', 'philips', 'haier', 'konka', 'kejian', 'lenovo', 'benq', 'mot', 'soutec', 'nokia', 'sagem', 'sgh',   'sed', 'capitel', 'panasonic', 'sonyericsson', 'sharp', 'amoi', 'panda', 'zte'); $pad_list = array('pad', 'gt-p1000'); $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if(dstrpos($useragent, $pad_list)) {  return false; } if(($v = dstrpos($useragent, $mobilebrowser_list, true))){  $_G['mobile'] = $v;  return '1'; } if(($v = dstrpos($useragent, $touchbrowser_list, true))){  $_G['mobile'] = $v;  return '2'; } if(($v = dstrpos($useragent, $wmlbrowser_list))) {  $_G['mobile'] = $v;  return '3'; //wml版 } $brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop'); if(dstrpos($useragent, $brower)) return false; $_G['mobile'] = 'unknown';//对于未知类型的浏览器,通过$_GET['mobile']参数来决定是否是手机浏览器 if(isset($_G['mobiletpl'][$_GET['mobile']])) {  return true; } else {  return false; }}/** * 判断$arr中元素字符串是否有出现在$string中 * @param  $string     $_SERVER['HTTP_USER_AGENT']  * @param  $arr          各中浏览器$_SERVER['HTTP_USER_AGENT']中必定会包含的字符串 * @param  $returnvalue 返回浏览器名称还是返回布尔值,true为返回浏览器名称,false为返回布尔值【默认】* @程序员人生 wfuyu.com 2016-0317 */function dstrpos($string, $arr, $returnvalue = false) { if(empty($string)) return false; foreach((array)$arr as $v) {  if(strpos($string, $v) !== false) {   $return = $returnvalue ? $v : true;   return $return;  } } return false;}

The second step is to use the code jump on the mobile phone. The code is as follows

function wappc($ac='towap'){  $is_wap=checkmobile();  if($is_wap){  //手机端     if($_SERVER['HTTP_HOST']=='www.wfuyu.com' && $_GET['b']!='topc'){   $url='http://m.wfuyu.com'.$_SERVER['REQUEST_URI'];     header('Location: '.$url); }      }else{  //PC端    }

There is a note here. In my method, the mobile URL must be synchronized with the computer URL. For example, the computer address is www.xxx.com/123.com, then the corresponding mobile phone address should be m.xxx.com/123.com

Step 3: Call the code in step 2 in front of the head of the mobile phone

Here is an explanation. We often see that some mobile websites will display the computer version on their homepage. Link, if you click on the computer side at this time, it will not jump to the mobile phone side. Corresponding processing will be done here. For example, we add a get tag b=topc after the link, and then perform judgment and filtering in the second step function. Can!

The above is the detailed content of What is the php mobile phone jump code?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn