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 相关文章推荐
第五节 克隆 [5]
Oct 09 PHP
一个PHP模板,主要想体现一下思路
Dec 25 PHP
经典的PHPer为什么被认为是草根?
Apr 02 PHP
PHP页面间参数传递的四种方法详解
Jun 09 PHP
解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别
Jun 24 PHP
对PHP语言认识上需要避免的10大误区
Jun 12 PHP
php面象对象数据库操作类实例
Dec 02 PHP
使用PHP+AJAX让WordPress动态加载文章的教程
Dec 11 PHP
laravel中短信发送验证码的实现方法
Apr 25 PHP
PDO::commit讲解
Jan 27 PHP
php常用日期时间函数实例小结
Jul 04 PHP
PHP isset()及empty()用法区别详解
Aug 29 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里得到前天和昨天的日期的代码
2007/08/16 PHP
php 生成随机验证码图片代码
2010/02/08 PHP
PHP贪婪算法解决0-1背包问题实例分析
2015/03/23 PHP
浅析Yii2 gridview实现批量删除教程
2016/04/22 PHP
php判断目录存在的简单方法
2019/09/26 PHP
jQuery 使用手册(六)
2009/09/23 Javascript
用JS实现3D球状标签云示例代码
2013/12/01 Javascript
jQuery 顶部导航跟随滚动条滚动固定浮动在顶部
2014/06/06 Javascript
QQ空间顶部折页撕开效果示例代码
2014/06/15 Javascript
javascript实现图片循环渐显播放的方法
2015/02/24 Javascript
Jquery+Ajax+PHP+MySQL实现分类列表管理(下)
2015/10/28 Javascript
利用CSS3在Angular中实现动画
2016/01/15 Javascript
TypeScript Type Innference(类型判断)
2016/03/10 Javascript
bootstrap datetimepicker日期插件超详细使用方法介绍
2017/02/23 Javascript
利用jQuery实现简单的拖曳效果实例代码
2017/10/20 jQuery
Javascript实现html转pdf高清版(提高分辨率)
2020/02/19 Javascript
Vue路由守卫及页面登录权限控制的设置方法(两种)
2020/03/31 Javascript
[01:10:16]DOTA2上海特级锦标赛B组资格赛#2 Fnatic VS Spirit第一局
2016/02/27 DOTA
python判断、获取一张图片主色调的2个实例
2014/04/10 Python
Python实现的ini文件操作类分享
2014/11/20 Python
Python的组合模式与责任链模式编程示例
2016/02/02 Python
Python使用Matplotlib实现雨点图动画效果的方法
2017/12/23 Python
python 循环读取txt文档 并转换成csv的方法
2018/10/26 Python
django表单的Widgets使用详解
2019/07/22 Python
Python+Pyqt实现简单GUI电子时钟
2021/02/22 Python
Python序列对象与String类型内置方法详解
2019/10/22 Python
CSS3中HSL和HSLA的简单使用示例
2015/07/14 HTML / CSS
Html5监听手机摇一摇事件的实现
2019/11/07 HTML / CSS
Fashion Eyewear美国:英国线上设计师眼镜和太阳镜的零售商
2016/08/15 全球购物
英国珠宝钟表和家居礼品精品店:David Shuttle
2018/02/24 全球购物
中学生学习生活的自我评价
2013/10/26 职场文书
地震捐款倡议书
2014/08/29 职场文书
会计试用期自我评价
2014/09/19 职场文书
农业项目投资意向书
2015/05/09 职场文书
幼儿园小班开学寄语(2016秋季)
2015/12/03 职场文书
2017元旦、春节期间廉洁自律承诺书
2016/03/25 职场文书