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读写文件的方法(生成HTML)
Nov 27 PHP
PHP 编程安全性小结
Jan 08 PHP
php下保存远程图片到本地的办法
Aug 08 PHP
解析PHP中的正则表达式以及模式匹配
Jun 19 PHP
PHP Global定义全局变量使用说明
Aug 15 PHP
php获取表单中多个同名input元素的值
Mar 20 PHP
php通过ajax实现双击table修改内容
Apr 28 PHP
PHP中的reflection反射机制测试例子
Aug 05 PHP
php计划任务之ignore_user_abort函数实现方法
Jan 08 PHP
Laravel中使用自己编写类库的3种方法
Feb 10 PHP
YII视图整合kindeditor扩展的方法
Jul 13 PHP
php查看一个变量的占用内存的实例代码
Mar 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下一个非常全面获取图象信息的函数
2008/11/20 PHP
PHP高并发和大流量解决方案整理
2019/12/24 PHP
JavaScript在IE和Firefox浏览器下的7个差异兼容写法小结
2010/06/18 Javascript
javascript学习笔记(十七) 检测浏览器插件代码
2012/06/20 Javascript
Javascript实现重力弹跳拖拽运动效果示例
2013/06/28 Javascript
jquery禁止输入数字以外的字符的示例(纯数字验证码)
2014/04/10 Javascript
使用jquery.qrcode生成彩色二维码实例
2014/08/08 Javascript
JavaScript判断字符长度、数字、Email、电话等常用判断函数分享
2015/04/01 Javascript
JavaScript中使用Math.PI圆周率属性的方法
2015/06/14 Javascript
javascript实现rgb颜色转换成16进制格式
2015/07/10 Javascript
JS组件Bootstrap实现弹出框效果代码
2016/04/26 Javascript
概述javascript在Google IE中的调试技巧
2016/11/24 Javascript
javascript设计模式之单体模式学习笔记
2017/02/15 Javascript
Javascript中类式继承和原型式继承的实现方法和区别之处
2017/04/25 Javascript
分析JavaScript数组操作难点
2017/12/18 Javascript
AngularJS对动态增加的DOM实现ng-keyup事件示例
2018/03/12 Javascript
浅谈微信页面入口文件被缓存解决方案
2018/09/29 Javascript
vue绑定class的三种方法
2020/12/24 Vue.js
深入理解Python中字典的键的使用
2015/08/19 Python
python实现车牌识别的示例代码
2019/08/05 Python
Python dict和defaultdict使用实例解析
2020/03/12 Python
Lyle & Scott苏格兰金鹰官网:英国皇室御用品牌
2018/05/09 全球购物
学校岗位设置方案
2014/01/16 职场文书
计算机售后服务承诺书
2014/05/30 职场文书
2014年精神文明建设工作总结
2014/11/19 职场文书
2014年乡镇人大工作总结
2014/11/25 职场文书
大学生学期个人总结
2015/02/12 职场文书
新郎结婚保证书
2015/02/26 职场文书
致短跑运动员加油稿
2015/07/21 职场文书
小学三年级数学教学反思
2016/02/16 职场文书
《检阅》教学反思
2016/02/22 职场文书
六年级语文教学反思
2016/03/03 职场文书
alibaba seata服务端具体实现
2022/02/24 Java/Android
JS实现数组去重的11种方法总结
2022/04/04 Javascript
victoriaMetrics库布隆过滤器初始化及使用详解
2022/04/05 Golang
SpringBoot详解整合Redis缓存方法
2022/07/15 Java/Android