PHP 判断终端是手机还是电脑访问网站代码
用thinkphp做底层框架,判断客户是用pc访问还是手机访问的。
<?php
$platform = platform();//检测访问平台
//print_r($_SERVER);DIE;
define('FILE_ROOT' , dirname(__FILE__));
define('APP_DEBUG' , true);
define('__BUICK__' , true);//
define('APP_PUBLIC_PATH' , '../Public');
define('THINK_PATH', $platform['THINK_PATH']);
define('APP_NAME' , $platform['APP_NAME']);
define('APP_PATH' , $platform['APP_PATH']);
require(THINK_PATH.'/ThinkPHP.php');
/**
* 返回平台参数
* 默认返回PC端配置
*/
function platform(){
$form = array( 'Pc' => array('THINK_PATH' => './App/ThinkPHP/','APP_NAME' => 'App','APP_PATH' => './App/' ) ,
'Moblie' => array('THINK_PATH' => './Moblie/ThinkPHP/','APP_NAME' => 'Moblie','APP_PATH' => './Moblie/' ) );
$form_key = is_mobile();
return $form[$form_key];
}
//判断是否属手机
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 = 'Pc';//默认PC端
foreach ($mobile_agents AS $device) {
if (stristr($user_agent, $device)) {
$is_mobile = 'Moblie';
break;
}
}
//针对移动端没有对应显示样式,需要显示PC端样式的活动
if(strstr($_SERVER['REQUEST_URI'],'?mobiletopc')){
$is_mobile = 'Pc';
}
return $is_mobile;
}
?>
PHP 判断终端是手机还是电脑访问网站代码的更多相关文章
- php判断终端是手机还是电脑访问网站代码
?php function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HTTP_X ...
- js判断是手机还是电脑访问网站
js判断是手机还是电脑访问网站 <script type="text/javascript"> <!- ...
- JS判断手机还是电脑访问网站
function check() { let browser = navigator.userAgent;//用户访问的类型 let phone = ["Android", &qu ...
- js判断终端是手机还是电脑
$(function(){ function browserRedirect() { var sUserAgent= navigator.userAgent.toLowerCase(); var bI ...
- PHP判断手机、电脑访问
/*判断用户是手机访问还是电脑访问*/$useragent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/(android|bb\d+|meego). ...
- PHP和JS判断手机还是电脑访问
当用户使用手机等移动终端访问网站时,我们可以通过程序检测用户终端类型,如果是手机用户,则引导用户访问适配手机屏幕的移动站点.本文将介绍分别使用PHP和JAVASCRIPT代码判断用户终端类型. PHP ...
- discuz php判断是手机访问还是电脑访问网站
首先在模块处填入代码: //手机网页跳转 //如果检测到访问的浏览器为下列一个指定的移动浏览器 则返回true function is_mobile(){ $regex_match="/(n ...
- javascript如何判断是手机还是电脑访问本网页
var system ={}; var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac ...
- java判断手机还是电脑访问
很多博客写的很复杂,没具体看.我只用下面的几行代码 String userAgent = req.getHeader("user-agent"); ) { //安卓 } ) || ...
随机推荐
- Windows网络命令的相关指令(1)
1.Ipconfig 该命令可以检查网络接口配置.如果用户系统不能到达远程主机,而同一系统的其他主机可以到达,那么用该命令对这种故障进行判断是有必要的.当主机能到达远程主机但不能到达本网主机时,则表示 ...
- 【剑指offer】面试题 31. 栈的压入、弹出序列
面试题 31. 栈的压入.弹出序列 NowCoder LeetCode 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如 ...
- java笔记3
面向对象的特点: 1.封装: 2.继承 3.多态 好处: 是一种符合人们思考习惯的思想 可以将复杂的事情简单化 将程序员从执行者变为指挥者 二 类与对象 成员变量与局部变量的区别: ...
- Centos 安装mysql8
Centos 安装mysql ,转载 https://www.cnblogs.com/funbin/p/11154784.html 1.下载mysql wget -i -c https://repo. ...
- Django框架深入了解_02(DRF之序列化、反序列化)
序列化:将Python对象准换成json格式的字符串,反之即为反序列化 DRF的序列化使用过程: 使用drf的序列化组件 -1 新建一个序列化类继承Serializer -2 在类中写要序列化的字段 ...
- asp.net core EF code first
以连接mysql数据库为例 一 安装组件 Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.Relational Microsof ...
- System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常。如果您在连接到 SQL Azure 数据库,请考虑使用 SqlAzureExecutionStrategy。
代码异常描述 ************** 异常文本 **************System.Data.Entity.Core.EntityException: 可能由于暂时性失败引发了异常.如果 ...
- VsCode 解决vim插件,不能使用ctrl+c的问题(目标卸载im)
VsCode中,使用VIM插件后,ctrl+c不能用 可以通过 File -> Preference -> Settings中 vim.useCtrlKeys 选项设置为 false ...
- centos 7.6 修改vim配色方案
cd ~ vim .vimrc colorscheme desert
- 使用PLSQL工具连接远程Oracle
在不安装Oracle的情况下使用PLSQL连接远程的数据库步骤: 1)官网下载Instant client工具包 http://www.oracle.com/us/solutions/index-09 ...