Thinkphp通过一个入口文件如何区分移动端和PC端


Posted in PHP onApril 18, 2017

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<?php
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG',True);
define('MULTI_MODULE', false);
// 获取当前文件所在的目录
define('DKSITE_TSDIR', dirname(__FILE__));
// 定义应用目录
define('APP_PATH',DKSITE_TSDIR.'/Application/');
//
function is_mobile(){ 
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
  $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte"); 
  $is_mobile = false; 
  foreach ($mobile_agents as $device) {//这里把值遍历一遍,用于查找是否有上述字符串出现过 
    if (stristr($user_agent, $device)) { //stristr 查找访客端信息是否在上述数组中,不存在即为PC端。 
      $is_mobile = true; 
      break; 
    } 
  } 
  return $is_mobile; 
}
//判断
if(is_mobile()){
 echo '您当前是在:手机端'; 
  // 手机端模块
 define('BIND_MODULE','Mobile');
}else{ 
 echo '您当前是在:pc端';
  // pc端前台模块
 define('BIND_MODULE','Home');      
} 
// 引入ThinkPHP入口文件
require dirname(__FILE__).'/ThinkPHP/ThinkPHP.php';

以上所述是小编给大家介绍的Thinkphp通过一个入口文件区分移动端和PC端的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

PHP 相关文章推荐
echo(),print(),print_r()之间的区别?
Nov 19 PHP
php中iconv函数使用方法
May 24 PHP
php 全文搜索和替换的实现代码
Jul 29 PHP
处理php自动反斜杠的函数代码
Jan 05 PHP
一个PHP并发访问实例代码
Sep 06 PHP
php使用curl存储cookie的示例
Mar 31 PHP
PHP中使用register_shutdown_function函数截获fatal error示例
Apr 21 PHP
WordPress用户登录框密码的隐藏与部分显示技巧
Dec 31 PHP
php5.2的curl-bug 服务器被php进程卡死问题排查
Sep 19 PHP
PHP构造二叉树算法示例
Jun 21 PHP
php删除一个路径下的所有文件夹和文件的方法
Feb 07 PHP
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
Apr 03 PHP
Yii2汉字转拼音类的实例代码
Apr 18 #PHP
php+resumablejs实现的分块上传 断点续传功能示例
Apr 18 #PHP
ZendFramework2连接数据库操作实例
Apr 18 #PHP
PHP实现的数独求解问题示例
Apr 18 #PHP
PHP使用finfo_file()函数检测上传图片类型的实现方法
Apr 18 #PHP
php实现不通过扩展名准确判断文件类型的方法【finfo_file方法与二进制流】
Apr 18 #PHP
基于thinkPHP3.2实现微信接入及查询token值的方法
Apr 18 #PHP
You might like
PHP中用header图片地址 简单隐藏图片源地址
2008/04/09 PHP
PHP中通过HTTP_USER_AGENT判断是否为手机移动终端的函数代码
2013/02/14 PHP
PHP中isset、empty的用法与区别示例详解
2020/11/05 PHP
初识Node.js
2014/09/03 Javascript
JavaScript之数组(Array)详解
2015/04/01 Javascript
JS实现可关闭的对联广告效果代码
2015/09/14 Javascript
js实现索引图片切换效果
2015/11/21 Javascript
图片懒加载插件实例分享(含解析)
2017/01/09 Javascript
Vue单文件组件基础模板小结
2017/08/10 Javascript
Angular中的$watch方法详解
2017/09/18 Javascript
js中async函数结合promise的小案例浅析
2019/04/14 Javascript
原生js实现each方法实例代码详解
2019/05/27 Javascript
js实现简单的贪吃蛇游戏
2020/04/23 Javascript
vue-cli 3如何使用vue-bootstrap-datetimepicker日期插件
2021/02/20 Vue.js
[01:01:35]Optic vs paiN 2018国际邀请赛小组赛BO2 第二场 8.19
2018/08/21 DOTA
python逐行读写txt文件的实例讲解
2018/04/03 Python
Python Pywavelet 小波阈值实例
2019/01/09 Python
python使用requests模块实现爬取电影天堂最新电影信息
2019/04/03 Python
Django学习笔记之为Model添加Action
2019/04/30 Python
python 应用之Pycharm 新建模板默认添加编码格式-作者-时间等信息【推荐】
2019/06/17 Python
pyqt5让图片自适应QLabel大小上以及移除已显示的图片方法
2019/06/21 Python
python cv2读取rtsp实时码流按时生成连续视频文件方式
2019/12/25 Python
Python3.9.1中使用split()的处理方法(推荐)
2021/02/07 Python
css3中单位px,em,rem,vh,vw,vmin,vmax的区别及浏览器支持情况
2016/12/06 HTML / CSS
西班牙在线宠物商店:zooplus.es
2017/02/24 全球购物
澳大利亚领先的美容护肤品零售商之一:SkincareStore
2018/01/22 全球购物
德国网上超市:myTime.de
2019/08/26 全球购物
文职个人求职信范文
2013/09/23 职场文书
人力资源行政经理自我评价
2013/10/23 职场文书
工业设计专业推荐信
2013/10/29 职场文书
高中班长自我鉴定
2013/12/20 职场文书
大学毕业生自荐书怎么写?
2014/01/06 职场文书
超越自我演讲稿
2014/05/21 职场文书
计算机网络及管理学专业求职信
2014/06/05 职场文书
烈士陵园扫墓感想
2015/08/07 职场文书
Python-OpenCV教程之图像的位运算详解
2021/06/21 Python