- 浏览: 13764478 次
- 性别:
- 来自: 洛杉矶
-
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
1. php mobile detect
<?php /** * Mobile Detect * * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @version SVN: $Id: Mobile_Detect.php 4 2011-05-26 08:04:20Z vic.stanciu@gmail.com $ */ class Mobile_Detect { protected $accept; protected $userAgent; protected $isMobile = false; protected $isAndroid = null; protected $isBlackberry = null; protected $isOpera = null; protected $isPalm = null; protected $isWindows = null; protected $isGeneric = null; protected $devices = array( "android" => "android", "blackberry" => "blackberry", "iphone" => "(iphone|ipod)", "opera" => "opera mini", "palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)", "windows" => "windows ce; (iemobile|ppc|smartphone)", "generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)" ); public function __construct() { $this->userAgent = $_SERVER['HTTP_USER_AGENT']; $this->accept = $_SERVER['HTTP_ACCEPT']; if (isset($_SERVER['HTTP_X_WAP_PROFILE'])|| isset($_SERVER['HTTP_PROFILE'])) $this->isMobile = true; elseif (strpos($this->accept,'text/vnd.wap.wml') > 0 || strpos($this->accept,'application/vnd.wap.xhtml+xml') > 0) $this->isMobile = true; else foreach ($this->devices as $device => $regexp) if ($this->isDevice($device)) $this->isMobile = true; } /** * Overloads isAndroid() | isBlackberry() | isOpera() | isPalm() | isWindows() | isGeneric() through isDevice() * * @param string $name * @param array $arguments * @return bool */ public function __call($name, $arguments) { $device = substr($name, 2); if ($name == "is" . ucfirst($device)) return $this->isDevice($device); else trigger_error("Method $name not defined", E_USER_ERROR); } /** * Returns true if any type of mobile device detected, including special ones * @return bool */ public function isMobile() { return $this->isMobile; } protected function isDevice($device) { $var = "is" . ucfirst($device); $return = $this->$var === null ? (bool) preg_match("/" . $this->devices[$device] . "/i", $this->userAgent) : $this->$var; if ($device != 'generic' && $return == true) $this->isGeneric = false; return $return; } }
Description
Mobile_Detect is a simple PHP class for easy detection of the most popular mobile devices platforms: Android, Blackberry, Opera Mini, Palm, Windows Mobile, as well as generic ones.
Usage
Include and instantiate the class:
include("Mobile_Detect.php"); $detect = new Mobile_Detect();
Check for a specific platform:
if ($detect->isAndroid()) { // code to run for the Google Android platform }
Available methods are isAndroid(), isBlackberry(), isOpera(), isPalm(), isWindows(), isGeneric(). Alternatively, if you are only interested in checking to see if the user is using a mobile device, without caring for specific platform:
if ($detect->isMobile()) { // any mobile platform }
来源:http://code.google.com/p/php-mobile-detect/
2. .htaccess
#redirect mobile browsers RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$ RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301] RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$ RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301] RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$ RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
或者
RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$ RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
发表评论
-
手机firebug查看网页代码 How to View Website Source Codes on iPad / iPhone
2016-04-26 02:41 1176You’re using your iPad to br ... -
Android模拟器genymotion的安装和使用
2016-03-18 01:16 2536Genymotion概述 Genymotion是一套完整的 ... -
编码之道:取个好名字很重要
2015-10-14 05:19 1181代码就是程序员的孩子,给“孩子”取个好听的名字很重 ... -
Genymotion - 强大好用高性能的 Android 模拟器 (在电脑流畅运行APK安卓软件游戏的利器)
2015-06-05 13:34 7402随着 Android 系统的应用和游戏越来越丰富,甚至有 ... -
收集几个移动平台浏览器的User-Agent
2014-07-23 02:33 3038List of all Mobile Browsers ... -
常用浏览器修改User-Agent的方法
2014-06-28 02:58 11074之前有介绍收集的几个移动平台浏览器的User-Agent,以 ... -
更简洁的方式修改Chrome的User Agent,轻松体验移动版网络
2014-06-28 02:53 6959国庆节在家宅着,使用3g上网卡上网,和在公司上网不一样的是 ... -
3个检测浏览器User-Agent信息的网站
2014-06-28 02:52 2573刚刚在收集各个移动平台浏览器的User-Agent(参见这 ... -
根据移动设备屏幕像素密度,给予不同分辨率的图片
2014-06-26 00:52 2983在出现iphone4之前的相当长的时间内,网站开发人员 ... -
视网膜New iPad与普通分辨率iPad页面的兼容处理
2014-06-26 00:44 1360一、这是篇经验分享 ... -
iOS8开发-Swift编程
2014-06-25 00:45 1927课时列表 章节1:第一个Swift应用 ... -
Swift中文教程(二十三) 高级运算符
2014-06-25 00:43 833除了基本操作符中所讲的运算符,Swift还有许多复杂的高级 ... -
Swift中文教程(二十二) 泛型
2014-06-25 00:35 1086泛型代码可以让你写出根据自我需求定义、适用于任何类型的,灵 ... -
Swift中文教程(二十一) 协议
2014-06-24 05:25 1467Protocol(协议)用于统一方法和属性的名称,而不实现任 ... -
Swift中文教程(二十) 扩展
2014-06-24 00:47 747扩展就是向一个已有的类、结构体或枚举类型添加新功能(fun ... -
Swift中文教程(十九) 类型嵌套
2014-06-24 00:44 936枚举类型常被用于实现特定类或结构体的功能。也能够在有多种变量 ... -
Swift中文教程(十八) 类型检查
2014-06-24 00:41 787类型检查是一种检查类实例的方式,并且或者也是让实例作为它的 ... -
Swift中文教程(十七) 可选链
2014-06-17 05:11 911可选链(Optional Chaining)是一种可以请求 ... -
Swift中文教程(十六) 自动引用计数
2014-06-17 05:05 1298Swift使用自动引用计数(ARC)来管理应用程序的内存使 ... -
Swift中文教程(十五) 析构
2014-06-17 04:57 1045在一个类的实例被释放之前,析构函数会被调用。用关键字dei ...
相关推荐
Mobile-Detect-2.8.12版本的压缩包中可能包含了类文件、示例代码和其他辅助资源,帮助开发者快速理解和集成这个库。在使用时,务必遵循官方文档或示例,以确保正确无误地引入和使用Mobile-Detect。 总之,Mobile-...
《Mobile-Detect-2.6.9:轻松识别移动设备的PHP解决方案》 在现代互联网技术中,响应式设计已经成为网站开发的必备要素,而针对不同设备提供优化的用户体验是关键。Mobile-Detect-2.6.9是一个专门用于检测移动设备...
除了基本的设备检测,`laravel-mobile-detect`还提供了许多其他功能,如检测特定品牌和型号的设备,检测设备特性(如触摸屏支持),甚至可以检测设备的操作系统版本。这使得开发者能更精细地控制用户体验,比如根据...
要使用 `Mobile-Detect-in-php`,你需要先下载并解压文件 `Mobile-Detect-in-php-master`,然后将 `Mobile_Detect.php` 文件引入你的PHP项目中。例如: ```php require_once 'path/to/Mobile_Detect.php'; $detect ...
1. 首先,需要引入Mobile_Detect类文件,通常位于压缩包中的`Mobile-Detect-2.7.9/Mobile_Detect.php`。 ```php require_once 'path/to/Mobile-Detect-2.7.9/Mobile_Detect.php'; ``` 2. 创建一个Mobile_Detect对象...
Mobile Detect是一个PHP类,通过User-Agent检测各种手机设备,并结合HTTP Header来检测移动设备环境。该类库最强大的地方是,它有一个非常完整的库,可以检测出所用的设备类型(包括操作类型、以及手机品牌等都能...
include('sstn/mobile_device_detect.php'); mobile_device_detect(false,true,true,'m/index.php',false); 2、上传附件中的mobile_device_detect.php到sstn目录。没有就在根目录新建一个。 说明。代码中的"m...
Mobile Detect是用于检测移动设备(包括平板电脑)的轻量级PHP类。 它结合使用User-Agent字符串和特定的HTTP标头来检测移动环境。 为什么 您网站的内容策略很重要! 您需要一个完整的工具包来提供经过优化,快速且...
安装ipub / mobile-detect的最佳方法是使用 : $ composer require ipub/mobile-detect 之后,您必须在config.neon中注册扩展名。 extensions : mobileDetect : IPub\MobileDetect\DI\MobileDetectExtension ...
Mobile-Detect-2.6.4.zip包含了这个库的最新版本2.6.4,它支持识别众多设备,如iPhone、iPod、Windows Phone、Android设备以及传统的个人电脑。 在PHP中,Mobile-Detect通过分析用户浏览器的User-Agent字符串来判断...
4. **第三方库**:为了更准确地识别各种设备,可以使用第三方库,如提供的"Mobile-Detect-2.8.31"。这是一个轻量级的PHP类,它包含了大量预定义的设备模式,可以识别超过1500种不同的手机型号。使用这个库,只需引入...
此外,Mobile Detect类库也需要定期更新,以纳入最新的设备和操作系统信息,确保检测结果的准确性。这是因为移动设备市场更新迅速,不断有新设备和新系统出现,而User-Agent字符串也会随之变化。 在实现不同设备...
在这个话题中,我们将深入探讨如何利用PHP进行移动终端检测,并以“Mobile-Detect-2.8.0”这个库为例进行解析。 Mobile-Detect是一个用PHP编写的轻量级类库,它专门用于检测移动设备,包括手机、平板电脑以及现代...
'version' => $detect->getScriptVersion(), // All headers that trigger 'isMobile' to be 'true', // before reaching the User-Agent match detection. 'headerMatch' => $detect->...
关于Mobile Detect是用于检测移动设备(包括平板电脑)的轻量级PHP类。 它使用User-Agent字符串组合格言:“每个企业都应该具有检测脚本来检测移动阅读器。” 关于Mobile Detect是用于检测移动设备(包括平板电脑)...
Mobile-Detect-2.6.4是一个流行的PHP库,专门用于检测设备类型,它提供了丰富的功能来识别各种移动设备。 Mobile-Detect库基于HTTP_USER_AGENT头信息来判断设备类型,这是一个服务器接收到的HTTP请求头,其中包含了...
在PHP编程中,获取手机或PC的型号与系统型号对于开发者来说是非常实用的功能,尤其是在进行设备适配或者数据分析时。本文将深入探讨如何利用PHP实现这些功能。 首先,我们要了解PHP是一个服务器端脚本语言,主要...
if ($detect->isMobile() && !$detect->isTablet()) { echo "访问者使用的是手机设备"; } else { echo "访问者可能是桌面用户或平板用户"; } ``` 在这段代码中,我们首先引入了detectmobilebrowsers库,然后创建...
Mobile Detect是一个PHP类,通过User-Agent检测各种手机设备,并结合HTTP Header来检测移动设备环境。该类库最强大的地方是,它有一个非常完整的库,可以检测出所用的设备类型(包括操作类型、以及手机品牌等都能...
下载地址http://code.google.com/p/php-mobile-detect/ 程序就是一个文件,下载之后直接引用就...if ($detect->isMobile()) { // any mobile platform echo ‘isMobile’;}else{ echo ‘isPC’;}?> 您可能感兴趣