<?php
/**
* 判断是否是通过手机访问
* @return bool 是否是移动设备
*/
public function isMobile() {
//判断手机发送的客户端标志
if(isset($_SERVER['HTTP_USER_AGENT'])) {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$clientkeywords = array(
'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-'
,'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini',
'operamobi', 'opera mobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile'
);
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if(preg_match("/(".implode('|',$clientkeywords).")/i",$userAgent)&&strpos($userAgent,'ipad') === false)
{
return true;
}
}
return false;
}
附:各移动浏览器的http user-agent:
一、微信的http user-agent(关键词MicroMessenger)
1. Iphone(苹果)平台微信的ucweb的useragent:
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko)
Mobile/9B176 MicroMessenger/4.3.2
1
2
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko)
Mobile/9B176 MicroMessenger/4.3.2
2. Android(安卓)平台微信的ucweb的useragent:
Mozilla/5.0 (<span class='wp_keywordlink'><a href="http://www.aiezu.com/category/system/linux" title="Linux系统相关文章" target="_blank">linux</a></span>; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1
(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255
1
2
Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1
(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255
二、UC浏览器的http user-agent(关键词UCWEB)
1. android平台:
android平台ucweb急速模式开启下ucweb浏览器useragent:
UCWEB/2.0 (Linux; U; Adr 2.3; zh-CN; MI-ONEPlus) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
1
UCWEB/2.0 (Linux; U; Adr 2.3; zh-CN; MI-ONEPlus) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
android平台ucweb急速模式关闭状态下的http_user_agent:
Mozilla/5.0 (Linux; U; Android 2.3; zh-CN; MI-ONEPlus) AppleWebKit/534.13 (KHTML, like Gecko)
UCBrowser/8.6.0.199 U3/0.8.0 Mobile Safari/534.13
1
2
Mozilla/5.0 (Linux; U; Android 2.3; zh-CN; MI-ONEPlus) AppleWebKit/534.13 (KHTML, like Gecko)
UCBrowser/8.6.0.199 U3/0.8.0 Mobile Safari/534.13
2. iPhone 平台
iPhone 平台极速模式开启状态下ucweb浏览器useragent:
UCWEB/2.0 (iOS; U; iPh OS 4_3_2; zh-CN; iPh4) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
1
UCWEB/2.0 (iOS; U; iPh OS 4_3_2; zh-CN; iPh4) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
iPhone 平台极速模式关闭状态下 UA 示例如下:(OBUA 为自带浏览器 UA)
OBUA UCBrowser/8.6.0.199 Mobile
1
OBUA UCBrowser/8.6.0.199 Mobile
3. iPad 平台
ipad平台下ucweb浏览器useragent:
Mozilla/5.0 (iPad; U; CPU OS 6_0 like Mac OS X; zh-CN; iPad2) AppleWebKit/534.13
(KHTML, like Gecko) UCBrowser/8.6.0.199 U3/0.8.0 Safari/534.13
1
2
Mozilla/5.0 (iPad; U; CPU OS 6_0 like Mac OS X; zh-CN; iPad2) AppleWebKit/534.13
(KHTML, like Gecko) UCBrowser/8.6.0.199 U3/0.8.0 Safari/534.13
4. windows Phone平台
WP平台下ucweb浏览器useragent:
WP平台极速模式开启状态下:(以 Nokia 900 为例)
UCWEB/2.0 (Windows; U; wds7.10; zh-CN; Nokia 900) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
1
UCWEB/2.0 (Windows; U; wds7.10; zh-CN; Nokia 900) U2/1.0.0 UCBrowser/8.6.0.199 U2/1.0.0 Mobile
5. 诺基亚平台
诺基亚手机Symbian&Java平台ucweb浏览器useragen:
Nokia 5800 XpressMusic/UCWEB8.9.0.253/50/999
1
Nokia 5800 XpressMusic/UCWEB8.9.0.253/50/999