/**
* 获取客户端浏览器信息
* @param null
* @author shouqiang
* @return string
*/
function get_broswer(){
$sys = $_SERVER['HTTP_USER_AGENT']; //获取用户代理字符串
if (stripos($sys, "Firefox/") > 0) {
preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
$exp[0] = "Firefox";
$exp[1] = $b[1]; //获取火狐浏览器的版本号
} elseif (stripos($sys, "Maxthon") > 0) {
preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou);
$exp[0] = "Maxthon";
$exp[1] = $aoyou[1];
} elseif (stripos($sys, "MSIE") > 0) {
preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
$exp[0] = "IE";
$exp[1] = $ie[1]; //获取IE的版本号
} elseif (stripos($sys, "OPR") > 0) {
preg_match("/OPR\/([\d\.]+)/", $sys, $opera);
$exp[0] = "Opera";
$exp[1] = $opera[1]; //获取opera浏览器版本号,今天下载一个opera浏览器做测试,发现opera竟然也换成谷歌的内核了,囧
} elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){
preg_match("/rv:([\d\.]+)/", $sys, $IE);//判断IE11非兼容模式
$exp[0] = "IE";
$exp[1] = $IE[1];
} elseif(!stripos($sys,'Chrome/') && stripos($sys,'AppleWebKit/')>0 && stripos($sys,'Safari/')>0){ // Safari浏览器
preg_match("/Version\/([\d\.]+)/", $sys, $Safari);
$exp[0] = "Safari";
$exp[1] = $Safari[1];
} elseif(stripos($sys,'Chrome/') && stripos($sys,'AppleWebKit/')>0 && stripos($sys,'UBrowser/')>0){ // Safari浏览器
preg_match("/UBrowser\/([\d\.]+)/", $sys, $UC);
$exp[0] = "UC";
$exp[1] = $UC[1];
} elseif (stripos($sys, "Chrome") > 0) {
preg_match("/Chrome\/([\d\.]+)/", $sys, $google);
$exp[0] = "Chrome";
$exp[1] = $google[1]; //获取google chrome的版本号
} else {
$exp[0] = "unknown";
$exp[1] = "";
}
return $exp[0].'('.$exp[1].')';
}
/**
* 获取客户端操作系统信息
* @param null
* @author shouqiang
* @return string
*/
function get_os(){
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = false;
if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.0')>0) {
$os = 'Windows Vista';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.1')>0) {
$os = 'Windows 7';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.2')>0) {
$os = 'Windows 8';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 5.1')>0) {
$os = 'Windows XP';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 5')>0) {
$os = 'Windows 2000';
} else if (stripos($agent, 'linux')>0) {
$os = 'Linux';
} else if (stripos($agent, 'unix')>0) {
$os = 'Unix';
} else if (stripos($agent, 'sun')>0 && stripos($agent, 'os')>0) {
$os = 'SunOS';
} else if (stripos($agent, 'ibm')>0 && stripos($agent, 'os')>0) {
$os = 'IBM OS/2';
} else if (stripos($agent, 'Mac')>0 && stripos($agent, 'PC')>0) {
$os = 'Macintosh';
} else if (stripos($agent, 'PowerPC')>0) {
$os = 'PowerPC';
} else if (stripos($agent, 'FreeBSD')>0) {
$os = 'FreeBSD';
} else if (stripos($agent, 'win')>0 && stripos($agent, '95')>0) {
$os = 'Windows 95';
} else if (stripos($agent, 'win 9x')>0 && stripos($agent, '4.90')>0) {
$os = 'Windows ME';
} else if (stripos($agent, 'win')>0 && stripos($agent, '98')>0) {
$os = 'Windows 98';
} else if (stripos($agent, 'win')>0 && stripos($agent, '32')>0) {
$os = 'Windows 32';
} else if (stripos($agent, 'iPhone')>0) {
preg_match("/CPU ([^)]+) like Mac OS X/", $agent, $matches);
$os = isset($matches[1]) ? $matches[1] : 'iPhone';
} else if (stripos($agent, 'iPad')>0) {
$os = 'iPad';
} else if (stripos($agent, 'Mac OS')>0) {
$os = 'Mac OS';
} else if (stripos($agent, 'Android')>0) {
$os = 'Android';
} else {
$os = 'unknown';
}
return $os;
}
* 获取客户端浏览器信息
* @param null
* @author shouqiang
* @return string
*/
function get_broswer(){
$sys = $_SERVER['HTTP_USER_AGENT']; //获取用户代理字符串
if (stripos($sys, "Firefox/") > 0) {
preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
$exp[0] = "Firefox";
$exp[1] = $b[1]; //获取火狐浏览器的版本号
} elseif (stripos($sys, "Maxthon") > 0) {
preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou);
$exp[0] = "Maxthon";
$exp[1] = $aoyou[1];
} elseif (stripos($sys, "MSIE") > 0) {
preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
$exp[0] = "IE";
$exp[1] = $ie[1]; //获取IE的版本号
} elseif (stripos($sys, "OPR") > 0) {
preg_match("/OPR\/([\d\.]+)/", $sys, $opera);
$exp[0] = "Opera";
$exp[1] = $opera[1]; //获取opera浏览器版本号,今天下载一个opera浏览器做测试,发现opera竟然也换成谷歌的内核了,囧
} elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){
preg_match("/rv:([\d\.]+)/", $sys, $IE);//判断IE11非兼容模式
$exp[0] = "IE";
$exp[1] = $IE[1];
} elseif(!stripos($sys,'Chrome/') && stripos($sys,'AppleWebKit/')>0 && stripos($sys,'Safari/')>0){ // Safari浏览器
preg_match("/Version\/([\d\.]+)/", $sys, $Safari);
$exp[0] = "Safari";
$exp[1] = $Safari[1];
} elseif(stripos($sys,'Chrome/') && stripos($sys,'AppleWebKit/')>0 && stripos($sys,'UBrowser/')>0){ // Safari浏览器
preg_match("/UBrowser\/([\d\.]+)/", $sys, $UC);
$exp[0] = "UC";
$exp[1] = $UC[1];
} elseif (stripos($sys, "Chrome") > 0) {
preg_match("/Chrome\/([\d\.]+)/", $sys, $google);
$exp[0] = "Chrome";
$exp[1] = $google[1]; //获取google chrome的版本号
} else {
$exp[0] = "unknown";
$exp[1] = "";
}
return $exp[0].'('.$exp[1].')';
}
/**
* 获取客户端操作系统信息
* @param null
* @author shouqiang
* @return string
*/
function get_os(){
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = false;
if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.0')>0) {
$os = 'Windows Vista';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.1')>0) {
$os = 'Windows 7';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 6.2')>0) {
$os = 'Windows 8';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 5.1')>0) {
$os = 'Windows XP';
} else if (stripos($agent, 'win')>0 && stripos($agent, 'nt 5')>0) {
$os = 'Windows 2000';
} else if (stripos($agent, 'linux')>0) {
$os = 'Linux';
} else if (stripos($agent, 'unix')>0) {
$os = 'Unix';
} else if (stripos($agent, 'sun')>0 && stripos($agent, 'os')>0) {
$os = 'SunOS';
} else if (stripos($agent, 'ibm')>0 && stripos($agent, 'os')>0) {
$os = 'IBM OS/2';
} else if (stripos($agent, 'Mac')>0 && stripos($agent, 'PC')>0) {
$os = 'Macintosh';
} else if (stripos($agent, 'PowerPC')>0) {
$os = 'PowerPC';
} else if (stripos($agent, 'FreeBSD')>0) {
$os = 'FreeBSD';
} else if (stripos($agent, 'win')>0 && stripos($agent, '95')>0) {
$os = 'Windows 95';
} else if (stripos($agent, 'win 9x')>0 && stripos($agent, '4.90')>0) {
$os = 'Windows ME';
} else if (stripos($agent, 'win')>0 && stripos($agent, '98')>0) {
$os = 'Windows 98';
} else if (stripos($agent, 'win')>0 && stripos($agent, '32')>0) {
$os = 'Windows 32';
} else if (stripos($agent, 'iPhone')>0) {
preg_match("/CPU ([^)]+) like Mac OS X/", $agent, $matches);
$os = isset($matches[1]) ? $matches[1] : 'iPhone';
} else if (stripos($agent, 'iPad')>0) {
$os = 'iPad';
} else if (stripos($agent, 'Mac OS')>0) {
$os = 'Mac OS';
} else if (stripos($agent, 'Android')>0) {
$os = 'Android';
} else {
$os = 'unknown';
}
return $os;
}