php detect tablet,Mobile_Detect.php:判断移动设备类型的开源PHP类使用说明
首先推荐一个php轻量级识别类,Mobile-Detect 专门识别是手机端还是pc端访问网站,这样就可以根据访问的终端类型指向手机浏览器适配的网站还是pc浏览器的网站。
Mobile-Detect官网链接如下MobileDetect
下面是我写得简单的跳转适配PC端还是手机端的代码:
require_once'Mobile_Detect.php';//注意要引入Mobile_Detect.php 这个类在上文的连接中有下载链接
$detect=newMobile_Detect;
if($detect->isMobile()){
header('Location: http://127.0.0.1/MobileDetect/MobileDetect/mobile.html', true, 301);
echo"mobile";
}else{
header('Location: http://127.0.0.1/MobileDetect/MobileDetect/pc.html', true, 301);
echo"pc";
}
?>
测试你 的 浏览器 或 移动 设备 , 并 检查 该 结果 。
简单切换例子mobile和classic页面 视图 之间切换.
Mini tutorial in Spanish by Alejandro Palop.
// These lines are mandatory.这些线路是强制性的
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Basic detection.基本 检测
$detect->isMobile();
$detect->isTablet();
// Magic methods.魔术方法
$detect->isIphone();
$detect->isSamsung();
// [...]
// Alternative to magic methods. 助手方法
$detect->is('iphone');
// Find the version of component.找到组件的版本
$detect->version('Android');
// Additional match method.额外的正则匹配方法
$detect->match('regex.*here');
// Browser grade method.浏览器的分级方法$detect->mobileGrade();
// Batch methods.批量化方法
$detect->setUserAgent($userAgent);
$detect->setHttpHeaders($httpHeaders);
// Check for mobile environment.检查是否为 移动环境if ($detect->isMobile()) {
// Your code here.
}
// Check for tablet device.检查是否为 平板设备
if($detect->isTablet()){
// Your code here.
}
// Check for any mobile device, excluding tablets.检查任何移动设备,不包括平板
if ($detect->isMobile() && !$detect->isTablet()) {
// Your code here.
}
//保存值session以后使用session和优化代码的速度
if(!$_SESSION['isMobile']){
$_SESSION['isMobile'] = $detect->isMobile();
}
// Redirect the user to your mobile version of the site.将用户重定向到站点的移动版本
if($detect->isMobile()){
header('http://m.yoursite.com', true, 301);//改为自己的站点
}
// Include and instantiate the class.导入并实例化类
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).任何移动设备(电话或平板电脑)
if ( $detect->isMobile() ) {
}
// Any tablet device.任何平板设备
if( $detect->isTablet() ){
}
// Exclude tablets.移动非平板设备
if( $detect->isMobile() && !$detect->isTablet() ){
}
// Check for a specific platform with the help of the magic methods:使用魔术方法检测系统
if( $detect->isiOS() ){
}
if( $detect->isAndroidOS() ){
}
// Alternative method is() for checking specific properties.用is()方法检测特殊属性
// WARNING: this method is in BETA, some keyword properties will change in the future.
//警告:此方法处于测试阶段,某些关键字属性将在未来更改。
$detect->is('Chrome')$detect->is('iOS')$detect->is('UCBrowser')$detect->is('Opera')// [...]// Batch mode using setUserAgent():使用setuseragent()批处理模式$userAgents = array('Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19','BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',// [...]);foreach($userAgents as $userAgent){$detect->setUserAgent($userAgent);$isMobile = $detect->isMobile();$isTablet = $detect->isTablet();// Use the force however you want.}// Get the version() of components.获得版本// WARNING: this method is in BETA, some keyword properties will change in the future.$detect->version('iPad'); // 4.3 (float)$detect->version('iPhone') // 3.1 (float)$detect->version('Android'); // 2.1 (float)$detect->version('Opera Mini'); // 5.0 (float)// [...]
php detect tablet,Mobile_Detect.php:判断移动设备类型的开源PHP类使用说明相关推荐
- ios判断当前设备类型
ios判断当前设备类型 代码如下: + (NSString*) deviceString { // 需要#import "sys/utsname.h" struct utsname ...
- Swift4.0判断本函数是否在其它类有相同的方法
组件化开发模式化,为了减少AppDelegate.m做很多事情会做几个组件来分担它的功能,因此他们的函数名相同. Object C判断本函数是否在其它类有相同的方法很简单,通过_cmd就能很快判断出来 ...
- Java判断不为空的工具类总结
Java判断不为空的工具类总结 1.Java判断是否为空的工具类,可以直接使用.包含,String字符串,数组,集合等等. 1 package com.bie.util; 2 3 import jav ...
- 关于网页js判断“客户端设备类型是移动端还是PC端“的解决方法?
文章目录 网页中js如何判断设备类型是手机端还是pc端? 有时候会在项目中遇到设备类型判断的问题,这里和大家分享一个js判断设备类型的办法: userAgent 属性的值 代码块 网页中js如何判断设 ...
- java判断访问设备类型
目的:用java判断当前请求设备的类型(pc.手机.平板) 业务类型:例如在电商系统中,用户买商品下单时,平台需要判断该订单是从那个类型的设备中来的,以便后变得统计工作. 实现方法: import j ...
- 更优雅地判断iOS设备类型
随着iPhoneX的发布,导航栏高度在iPhone中也不再是一个64的常量了. 因此,很多地方需要针对齐刘海的导航栏高度做适配,目前网上很多关于判断是否为iPhoneX,使用了屏幕宽高来比较或者uts ...
- 如何判断蓝牙设备类型
我们在开发Android的蓝牙应用时,可能需要知道扫描到的蓝牙设备是什么类型,然后过滤掉不符合要求的设备,只保留符合要求的设备,例如我们在车载系统上开发蓝牙电话应用时,我们希望只显示手机蓝牙设备,那么 ...
- 简单的通过request判断客户端设备类型
String User_Agent = request.getHeader("User-Agent"); if (User_Agent.contains("Android ...
- 判断某值是否属于枚举类中的值_编写高质量可维护的代码之优化逻辑判断
if else.switch case 是日常开发中最常见的条件判断语句,这种看似简单的语句,当遇到复杂的业务场景时,如果处理不善,就会出现大量的逻辑嵌套,可读性差并且难以扩展. 编写高质量可维护的代 ...
最新文章
- Mybatis 3 返回布尔值,需要注意的地方
- 使用ip6tables禁用ipv6
- oracle没有groupby,oraclegroupby之后还可以groupby么
- 比较两个二维数组是否相等
- Android移动端音视频的快速开发教程(五)
- 如何避免大脑短路?用心理学分析重庆公交车坠江案
- 开源软件执照检查和工具探讨(Discuss the audit tools for open source license GPL/LGPL/MIT)
- LeetCode 279. Perfect Squares
- 更新sql语句 sql注入_SQL更新语句– SQL中的更新查询
- ssh-keygen+ssh-copy-id无密码登录远程LINUX主机(转载)
- 加密与解密 linux,security 02: 加密与解密 、 扫描与抓包 、 总结和答疑 、 SELinux安全防护(示例代码)...
- matlab机器人画圆
- Running “flutter pub get“ in xxx... 报错: Git error 443
- Java-茴香豆研究(一)
- Images Aesthetic Predictors Based on Weighted CNNs 论文翻译解读
- HDU6217 BBP Formula
- 最好用的项目流程管理工具 OmniPlan Pro 4.3.2 Mac版(内附安装包链接)
- 初等数论知识(附证明)
- 记一次腾讯社招前端面试(已拿到offer入职)
- https详解+密钥交换算法+公钥与私钥