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 相关文章推荐
PHP的FTP学习(三)
Oct 09 PHP
ZF等常用php框架中存在的问题
Jan 10 PHP
php 数组的合并、拆分、区别取值函数集
Feb 15 PHP
php开启安全模式后禁用的函数集合
Jun 26 PHP
php中拷贝构造函数、赋值运算符重载
Jul 25 PHP
thinkphp 多表 事务详解
Jun 17 PHP
php empty()与isset()区别的详细介绍
Jun 17 PHP
Yii调试SQL的常用方法
Jul 09 PHP
php获取文章内容第一张图片的方法示例
Jul 03 PHP
PHP文件系统管理(实例讲解)
Sep 19 PHP
php连接MSsql server的五种方法总结
Mar 04 PHP
PHP7修改的函数
Mar 09 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
中东人咖啡哲学
2021/03/03 咖啡文化
PHP 函数执行效率的小比较
2010/10/17 PHP
php学习笔记 php中面向对象三大特性之一[封装性]的应用
2011/06/13 PHP
PHP实现加密文本文件并限制特定页面的存取的效果
2016/10/21 PHP
总结PHP代码规范、流程规范、git规范
2018/06/18 PHP
jquery的ajax从纯真网(cz88.net)获取IP地址对应地区名
2009/12/02 Javascript
20个最新的jQuery插件
2012/01/13 Javascript
Extjs中TabPane如何嵌套在其他网页中实现思路及代码
2013/01/27 Javascript
计算新浪Weibo消息长度(还可以输入119字)
2013/07/02 Javascript
JavaScript原生对象之Date对象的属性和方法详解
2015/03/13 Javascript
JQuery.Ajax()的data参数类型实例详解
2015/11/20 Javascript
详解Nodejs的timers模块
2016/12/22 NodeJs
Bootstrap源码解读网格系统(3)
2016/12/22 Javascript
JavaScript变量类型以及变量作用域详解
2017/08/14 Javascript
快速将Vue项目升级到webpack3的方法步骤
2017/09/14 Javascript
js replace替换字符串同时替换多个方法
2018/11/27 Javascript
javascript删除数组元素的七个方法示例
2019/09/09 Javascript
node.js使用 http-proxy 创建代理服务器操作示例
2020/02/10 Javascript
el-table树形表格表单验证(列表生成序号)
2020/05/31 Javascript
[01:29:42]Liquid vs VP Supermajor决赛 BO 第一场 6.10
2018/07/05 DOTA
Python写的创建文件夹自定义函数mkdir()
2014/08/25 Python
itchat和matplotlib的结合使用爬取微信信息的实例
2017/08/25 Python
Python tkinter实现的图片移动碰撞动画效果【附源码下载】
2018/01/04 Python
python画一个玫瑰和一个爱心
2020/08/18 Python
Python eval的常见错误封装及利用原理详解
2019/03/26 Python
Pytorch 使用opnecv读入图像由HWC转为BCHW格式方式
2020/06/02 Python
canvas绘图按照contain或者cover方式适配并居中显示
2019/02/18 HTML / CSS
英国电气世界:Electrical World
2019/09/08 全球购物
澳大利亚网上书店:QBD
2021/01/09 全球购物
低碳生活倡议书
2014/04/14 职场文书
村庄绿化方案
2014/05/07 职场文书
师德先进个人材料
2014/12/20 职场文书
孟佩杰观后感
2015/06/17 职场文书
2016年大学生社会实践心得体会
2015/10/09 职场文书
使用python如何删除同一文件夹下相似的图片
2021/05/07 Python
详解nginx安装过程并代理下载服务器文件
2022/02/12 Servers