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"); ) { //安卓 } ) || ...
随机推荐
- Clean code 关于注释、函数、命名的感想
最近在看代码整洁之道(Clean code)这本书,其实看的有点痛苦,因为越看就会越想自己写的代码是什么鬼?一些不知所云的命名,不整洁的代码格式,本想诠释代码的意思却添加了一段段废话,还有那些被强制加 ...
- Qt5 QtQuick系列----QtQuick的Secne Graph剖析(1)
教是言词, 实不是道,道本无言, 言说是妄.------- 达摩 Qt 5提出了一个新的渲染底层,以替代Qt4时期的Graphics View,这个渲染底层就是Scene Graph.Scene Gr ...
- php常用的验证
<?php namespace Vendor\Func; /** * 常用的验证 * Class Verify * @package Vendor\Func */ class Verify { ...
- 15 Filter过滤器和Listener监听器
1.Filter:过滤器 (1) 概念:生活中的过滤器:净水器,空气净化器,土匪.web中的过滤器:当访问服务器的资源时,过滤器可以将请求拦截下来,完成一些特殊的功能.过滤器的作用:一般用于完成通用的 ...
- [转帖]Helm V2 迁移到 V3 版本
Helm V2 迁移到 V3 版本 -- :: Mr-Liuqx 阅读数 63更多 分类专栏: kubernetes 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上 ...
- Python-11-生成器
一.定义 可以理解为一种数据类型,这种数据类型自动实现了迭代器协议(其他数据类型需要调用__iter__方法),所以生成器就是一种迭代器. 二.生成器的两种形式 1. 生成器函数 使用yield代替r ...
- python基础 — 异常处理
什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常. 异常是Python对象,表示一个错误. 当Pyth ...
- hdu1016 Prime Ring Problem【素数环问题(经典dfs)】
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Latex局部字体大小设置
tex 设置字体大小命令由小到大依次为: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \ ...
- ppt thinkcell-Thinkcell: 一款强大的专业图表制作工具
https://jingyan.baidu.com/article/6dad50750e6121a123e36e00.html