手机端访问时调用Wap手机模块,实现在手机端访问时展示出手机网站,无需跳转域名
首先我们在./Application/Common/Conf/ 目录下建立两个公共配置文件:config.php 和config_wap.php

config.php 中:

  1. return array(
  2. 'DEFAULT_MODULE'=>'Index',
  3. 'DEFAULT_CONTROLLER'=>'Index',
  4. 'DEFAULT_ACTION'=>'index',
  5. )
复制代码

config_wap.php 中:

  1. return array(
  2. 'DEFAULT_MODULE'=>'Wap',
  3. 'DEFAULT_CONTROLLER'=>'Index',
  4. 'DEFAULT_ACTION'=>'index',
  5. )
复制代码

然后在入口文件 index.php 中加入手机端判断方法(建议放到最下面):

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

然后,我们开始用关键的APP_STATUS来调用不同的模块:
在index.php文件中的21行后面也就是“定义应用目录”结束后,加入代码:

  1. if(is_mobile_request()){
  2. define('APP_STATUS','config_wap');
  3. }else{
  4. define('APP_STATUS','Index');
  5. }
复制代码

大功告成。
参考文档:http://document.thinkphp.cn/manual_3_2.html#load_config

TP3.2.x判断手机端访问并设置默认访问模块的方法 - ThinkPHP框架的更多相关文章

  1. ThinkPHP3.2判断手机端访问并设置默认访问模块的方法

    ThinkPHP3.2判断是否为手机端访问并跳转到另一个模块的方法 目录结构 公共模块Common,Home模块,Mobile模块 配置Application/Common/Conf/config.p ...

  2. js判断手机端操作系统(Andorid/IOS)

    非常实用的js判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面 androidURL = "http://xxx/xxx.apk"; var browser = ...

  3. js判断手机端操作系统的两种方法

    //判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面 androidURL ="http://xxx/xxx.apk"; var browser = { ver ...

  4. 原生js为页面添加爱心特效和判断手机端还是电脑端登录

    <!-- 为页面添加爱心特效 --> <script type="text/javascript"> (function (window, document ...

  5. dedecms织梦手机端文章内容页图片不能自适应解决方法

    dedecms织梦手机端文章内容页图片不能自适应解决方法: 方法一修改手机端文章页模板代码: 找到并打开手机端的文章内容页模板,将里面的{dede:field.body/}标签修改一下,改为如下的标签 ...

  6. JavaScript 判断手机端访问并跳转 redirect mobile

    假如你的手机端网站在 /m 目录下 (function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer| ...

  7. PHP判断用户是手机端?还是浏览器端访问?

    function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ' ...

  8. js判断手机端

    if (window.location.toString().indexOf('pref=padindex') != -1) { } else { if (/AppleWebKit.*Mobile/i ...

  9. PHP 判断手机端还是web端

    function isMobile(){ // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) re ...

随机推荐

  1. JDK源码阅读--AbstractStringBuilder

    abstract class AbstractStringBuilder implements Appendable, CharSequence /** * The value is used for ...

  2. OpenCASCADE圆与平面求交

    OpenCASCADE圆与平面求交 eryar@163.com 在 解析几何求交之圆与二次曲面中分析了OpenCASCADE提供的类IntAna_IntConicQuad可以用来计算圆与二次曲面之间的 ...

  3. 转:Linux 文件IO理解

    源地址http://blog.csdn.net/lonelyrains/article/details/6604851 linux文件IO操作有两套大类的操作方式:不带缓存的文件IO操作,带缓存的文件 ...

  4. AppScan的基础使用

    AppScan是用于Web项目的安全测试工具,扫描网站所有url,自动测试是否存在各种类型的漏洞.AppScan安装在Windows环境上,版本越高,规则库越安全,扫描越全面.   1. 打开AppS ...

  5. vue 组件内引入外部在线js、css

    参考:https://blog.csdn.net/u010881899/article/details/80895661 例:引入element-ui js: mounted() { const oS ...

  6. DOS常用命令详解

    DOS常用命令详解 dir 列文件名 deltree 删除目录树 cls 清屏 cd 改变当前目录 copy 拷贝文件 diskcopy 复制磁盘 del 删除文件 format 格式化磁盘 edit ...

  7. python configparser模块详解

    此模块提供了一个实现基本配置语言的类 首先来看一个非常基本的配置文件,如下所示格式: [DEFAULT] ServerAliveInterval = 45 Compression = yes Comp ...

  8. Hbase实验:java创建和删除table

    开启zookeeper.hadoop.hbase: 打开eclipse创一个java project,然后导入所需jar包: 写好java代码,运行create,然后去hbase shell里查看: ...

  9. Leetcode201. Bitwise AND of Numbers Range数字范围按位与

    给定范围 [m, n],其中 0 <= m <= n <= 2147483647,返回此范围内所有数字的按位与(包含 m, n 两端点). 示例 1: 输入: [5,7] 输出: 4 ...

  10. AtCoder - 3959

    AtCoder - 3959https://vjudge.net/problem/1583855/origin求最长连续递增长度就行,答案是n-max(len) #include<iostrea ...