[普通]php获取客户端系统和游览器类型,版本号的接口

作者(passion) 阅读(1044次) 评论(0) 分类( html)
/**
 * 获取客户端游览器
 * @params $ua  User-Agent
 * @author haha 2016-01-21
 */
public function getClientBroswer($ua = '') {
$ua or $ua = $_SERVER['HTTP_USER_AGENT'];
//微信打开
if (stripos($ua, 'MicroMessenger')) {
preg_match('/MicroMessenger\/([\d\.]+)/i', $ua, $match);
return 'Wechat '. $match[1];
}
//获取火狐浏览器的版本号
if (stripos($ua, 'Firefox/')) {
preg_match('/Firefox\/([^;)]+)/i', $ua, $match);
$exp[0] = 'Firefox';
$exp[1] = $match[1];
}
//360游览器
else if(stripos($ua,'360SE')) {
$exp[0] = '360游览器';
$exp[1] = '';
}
//搜狗游览器
else if(stripos($ua, 'SE') && stripos($ua, 'MetaSr')) {
preg_match('/SE\s([\w\.]+)/i', $ua, $match);
$exp[0] = '搜狗';
$exp[1] = $match[1];
}
//获取google chrome的版本号
else if (stripos($ua, 'Chrome')) {
preg_match('/Chrome\/([\d\.]+)/', $ua, $match);
$exp[0] = 'Chrome';
$exp[1] = $match[1];
}
//遨游游览器
elseif (stripos($ua, 'Maxthon')) {
preg_match('/Maxthon([\s\d\.]+)/', $ua, $match);
$exp[0] = '傲游';
$exp[1] = $match[1];
}
//欧朋游览器
elseif (stripos($ua, 'opera')) {
preg_match('/opera\/([\d\.\/]+)/', $ua, $match);
$exp[0] = 'Opera';
$exp[1] = $match[1];
}
//win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配
else if(stripos($ua, 'Edge')) {
preg_match('/Edge\/([\d\.]+)/', $ua, $match);
$exp[0] = 'Edge';
$exp[1] = $match[1];
}
//UC游览器
else if(stripos($ua,'UCBrowser')) {
preg_match('/UCBrowser\/([\d\.]+)/', $ua, $match);
$exp[0] = 'UCBrowser ';
$exp[1] = $match[1];
}
//QQ游览器(note:移动端没有检测版本号)
else if(stripos($ua,'TencentTraveler') || stripos($ua,'QQBrowser')) {
preg_match('/TencentTraveler\s([\d\.]+)/', $ua, $match);
$exp[0] = 'QQ游览器';
$exp[1] = $match[1];
}
//百度游览器
else if(stripos($ua,'baidubrowser')) {
preg_match('/baidubrowser\/([\d\.]+)/', $ua, $match);
$exp[0] = '百度游览器';
$exp[1] = $match[1];
}
//IE11
else if(stripos($ua,'rv:')) {
preg_match('/rv:([\d\.]+)/', $ua, $match);
$exp[0] = 'IE';
$exp[1] = $match[1];
}
//移动设备的IE游览器
else if(stripos($ua, 'IEMobile')) {
preg_match('/IEMobile\/([\d\.]+)+/i', $ua, $match);
$exp[0] = 'IE';
$exp[1] = $match[1];
}
//获取IE的版本号
else if (stripos($ua, 'MSIE')) {
preg_match('/MSIE\s+([^;)]+)+/i', $ua, $match);
$exp[0] = 'IE';
$exp[1] = $match[1];
}
else {
$exp[0] = '未知浏览器';
$exp[1] = '';
}
return implode(' ',$exp);
}
/**
 * 获取客户端OS
 * @params $ua  User-Agent
 * @author haha 2016-01-21
 */
public function getClientOS($ua = '')
{
$ua or $ua = $_SERVER['HTTP_USER_AGENT'];
//window系统
if (stripos($ua, 'window')) {
$os = 'Windows';
if (preg_match('/nt 6.0/i', $ua)) {
$os .= ' Vista';
} else if (preg_match('/nt 6.1/i', $ua)) {
$os .= ' 7';
} else if (preg_match('/nt 6.2/i', $ua)) {
$os .= ' 8';
} else if (preg_match('/nt 10.0/i', $ua)) {
$os .= ' 10';
} else if (preg_match('/nt 5.1/i', $ua)) {
$os .= ' XP';
} else {
//其他window操作系统
}
}
else if (stripos($ua, 'android')) {
preg_match('/android\s([\d\.]+)/i', $ua, $match);
$os = 'Android ';
$os .= $match[1];
}
else if(preg_match('/iPhone|iPad|iPod/i',$ua)) {
preg_match('/OS\s([0-9_\.]+)/i', $ua, $match);
$os = 'IOS ';
$os .= str_replace('_','.',$match[1]);
}
else if (stripos($ua, 'mac os')) {
preg_match('/Mac OS X\s([0-9_\.]+)/i', $ua, $match);
$os = 'Mac OS X ';
$os .= str_replace('_','.',$match[1]);
}
else if (stripos($ua, 'unix')) {
$os = 'Unix';
}
else if (stripos($ua, 'linux')) {
$os = 'Linux';
}
else {
$os = 'Other';
}
return $os;
}


« 上一篇:wifi共享上网(至尊版wifi)
« 下一篇:ASP.NET附加数据库文件的方式,如何发布到IIS7而不导致SQLServer出错
在这里写下您精彩的评论
  • 微信

  • QQ

  • 支付宝

返回首页
返回首页 img
返回顶部~
返回顶部 img