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闭包和匿名函数使用的句法与普通函数相同,但闭包和匿名函数其实是伪装成函数的对象(Closure类的实例) 。下面给大家介绍PHP中的闭包和匿名函数知识,需要的朋友参考下吧
    2017-12-12
  • PHP获取本周所有日期或者最近七天所有日期的方法

    PHP获取本周所有日期或者最近七天所有日期的方法

    这篇文章主要介绍了PHP获取本周所有日期或者最近七天所有日期的方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-06-06
  • php头像上传预览实例代码

    php头像上传预览实例代码

    本篇文章主要介绍了php头像上传预览实例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • 简单谈谈PHP的垃圾回收机制

    简单谈谈PHP的垃圾回收机制

    这篇文章主要介绍了简单谈谈PHP的垃圾回收机制的相关资料,需要的朋友可以参考下
    2018-03-03
  • yii2.0整合阿里云oss删除单个文件的方法

    yii2.0整合阿里云oss删除单个文件的方法

    这篇文章主要介绍了yii2.0整合阿里云oss删除单个文件的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-09-09
  • PHP制作万年历

    PHP制作万年历

    本文主要介绍了使用PHP制作万年历的方法以及实现此功能的几个要点并提供了全部源代码,这里推荐给小伙伴们
    2015-01-01
  • 浅谈PHP值mysql操作类

    浅谈PHP值mysql操作类

    下面小编就为大家带来一篇浅谈PHP值mysql操作类。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-06-06
  • ThinkPHP2.0读取MSSQL提示Incorrect syntax near the keyword ''AS''的解决方法

    ThinkPHP2.0读取MSSQL提示Incorrect syntax near the keyword ''AS''

    这篇文章主要介绍了ThinkPHP2.0读取MSSQL提示Incorrect syntax near the keyword 'AS'的解决方法,需要的朋友可以参考下
    2014-06-06
  • php序列化函数serialize() 和 unserialize() 与原生函数对比

    php序列化函数serialize() 和 unserialize() 与原生函数对比

    这篇文章主要介绍了php序列化函数serialize() 和 unserialize() 与php原生序列化方法对比,有需要的小伙伴可以参考下。
    2015-05-05
  • thinkphp实现上一篇与下一篇的方法

    thinkphp实现上一篇与下一篇的方法

    这篇文章主要介绍了thinkphp实现上一篇与下一篇的方法,以实例形式对比分析了两种不同的实现方法供大家选择,方法二在方法一的基础上增加了判断的功能,是非常实用的技巧,需要的朋友可以参考下
    2014-12-12

最新评论