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

 更新时间:2017年04月18日 14:41:25   投稿:mrr  
这篇文章主要介绍了Thinkphp通过一个入口文件区分移动端和PC端的方法,需要的的朋友参考下吧

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

<?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面试题 试试看看你会不会也中招

    这篇文章主要介绍了几道坑人的PHP面试题,试试看看你会不会也中招,这些题目都用了一些障眼法,需要你有一双火眼金睛哦,需要的朋友可以参考下
    2014-08-08
  • 获取URL文件名后缀

    获取URL文件名后缀

    用php分析URL网址,可以得到文件名、目录路径,还有其它数据,原理就是使用PHP的explode函数分隔字符串。
    2013-10-10
  • WordPress免插件实现面包屑导航的示例代码

    WordPress免插件实现面包屑导航的示例代码

    这篇文章主要介绍了WordPress免插件实现面包屑导航,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-08-08
  • php之Smarty模板使用方法示例详解

    php之Smarty模板使用方法示例详解

    这篇文章主要介绍了php之Smarty模板的使用方法,需要的朋友可以参考下
    2014-07-07
  • php时间戳格式化显示友好的时间函数分享

    php时间戳格式化显示友好的时间函数分享

    在一些微博系统中经常要将时间于现在时间相比显示为多久以前发布的,如显示为:刚刚、5秒前、5小时前、5天前..这种显示非常的友好,那么我们怎么用php来实现呢,这就是本文探讨的内容,各位看官请仔细阅读下文
    2014-10-10
  • thinkPHP中volist标签用法示例

    thinkPHP中volist标签用法示例

    这篇文章主要介绍了thinkPHP中volist标签用法,结合实例形式分析了thinkPHP中volist标签的功能、属性及相关使用技巧,需要的朋友可以参考下
    2016-12-12
  • Yii使用DbTarget实现日志功能的示例代码

    Yii使用DbTarget实现日志功能的示例代码

    这篇文章主要介绍了Yii使用DbTarget实现日志功能的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-07-07
  • codeigniter使用技巧批量插入数据实例方法分享

    codeigniter使用技巧批量插入数据实例方法分享

    CI批量插入数据,CodeIgniter是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为 PHP 程序员建立功能完善的 Web 应用程序
    2013-12-12
  • 初识Laravel

    初识Laravel

    最近因为项目问题,接触到了Laravel框架,说说自己的使用感受吧。
    2014-10-10
  • 基于php实现随机合并数组并排序(原排序)

    基于php实现随机合并数组并排序(原排序)

    最近做了一个项目,其中有这样一个需求要实现,原有帖子列表A,现在需要在A中推广新业务B,那么需要在A列表中1:1混合B中的数据,随机混合,但是需要保持A和B两列原来的数据排序,本篇文章给大家介绍基于php实现随机合并数组并排序(原排序),需要的朋友参考下
    2015-11-11

最新评论