In php, if we want to obtain browser information, we can directly use $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]); and then make a further judgment to determine the user's browser version or model. I hope the following example will be helpful to everyone Helps.
The author below will introduce to you a php function that determines whether the user's browser is IE6. If so, it will return "true", otherwise it will return "false".
The code is as follows |
Copy code |
代码如下 |
复制代码 |
function isIE6() {
$userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
//从HTTP_USER_AGENT字段中获取用户浏览器信息
if (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
return true;
}
return false;
}
|
function isIE6() {
$userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
//Get user browser information from HTTP_USER_AGENT field
If (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
return true;
}
return false;
}
|
Complete example
代码如下 |
复制代码 |
function userBrowser(){
$user_OSagent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($user_OSagent,"Maxthon") && strpos($user_OSagent,"MSIE")) {
$visitor_browser ="Maxthon(Microsoft IE)";
}elseif(strpos($user_OSagent,"Maxthon 2.0")) {
$visitor_browser ="Maxthon 2.0";
}elseif(strpos($user_OSagent,"Maxthon")) {
$visitor_browser ="Maxthon";
}elseif(strpos($user_OSagent,"MSIE 9.0")) {
$visitor_browser ="MSIE 9.0";
}elseif(strpos($user_OSagent,"MSIE 8.0")) {
$visitor_browser ="MSIE 8.0";
}elseif(strpos($user_OSagent,"MSIE 7.0")) {
$visitor_browser ="MSIE 7.0";
}elseif(strpos($user_OSagent,"MSIE 6.0")) {
$visitor_browser ="MSIE 6.0";
} elseif(strpos($user_OSagent,"MSIE 5.5")) {
$visitor_browser ="MSIE 5.5";
} elseif(strpos($user_OSagent,"MSIE 5.0")) {
$visitor_browser ="MSIE 5.0";
} elseif(strpos($user_OSagent,"MSIE 4.01")) {
$visitor_browser ="MSIE 4.01";
}elseif(strpos($user_OSagent,"MSIE")) {
$visitor_browser ="MSIE 较高版本";
}elseif(strpos($user_OSagent,"NetCaptor")) {
$visitor_browser ="NetCaptor";
} elseif(strpos($user_OSagent,"Netscape")) {
$visitor_browser ="Netscape";
}elseif(strpos($user_OSagent,"Chrome")) {
$visitor_browser ="Chrome";
} elseif(strpos($user_OSagent,"Lynx")) {
$visitor_browser ="Lynx";
} elseif(strpos($user_OSagent,"Opera")) {
$visitor_browser ="Opera";
} elseif(strpos($user_OSagent,"Konqueror")) {
$visitor_browser ="Konqueror";
} elseif(strpos($user_OSagent,"Mozilla/5.0")) {
$visitor_browser ="Mozilla"; } elseif(strpos($user_OSagent,"Firefox")) {
$visitor_browser ="Firefox";
}elseif(strpos($user_OSagent,"U")) {
$visitor_browser ="Firefox";
$visitor_browser = "Other";
return $visitor_browser;
}
|
http://www.bkjia.com/PHPjc/628712.html
www.bkjia.comtrue
http: //www.bkjia.com/PHPjc/628712.html
TechArticleIn php, if we want to obtain browser information, we can directly use $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"] ); Then you can judge the user's browser version or model,...