天天看點

php:PHP擷取浏覽器的版本資訊

PHP語言:   PHP擷取浏覽器的版本資訊

//分析傳回使用者網頁浏覽器名稱,傳回的數組第一個為浏覽器名稱,第二個是版本号。
 functiongetBrowser() {
    $sys = $_SERVER['HTTP_USER_AGENT'];
    if (stripos($sys, "NetCaptor") >0) {
        $exp[0] ="NetCaptor";
        $exp[1] ="";
    } elseif (stripos($sys, "Firefox/")> 0) {
       preg_match("/Firefox\/([^;)]+)+/i", $sys,$b);
        $exp[0] ="Mozilla Firefox";
        $exp[1] =$b[1];
    } elseif (stripos($sys, "MAXTHON")> 0) {
       preg_match("/MAXTHON\s+([^;)]+)+/i", $sys,$b);
       preg_match("/MSIE\s+([^;)]+)+/i", $sys,$ie);
        // $exp =$b[0]." (IE".$ie[1].")";
        $exp[0] =$b[0] . " (IE" . $ie[1] . ")";
        $exp[1] =$ie[1];
    } elseif (stripos($sys, "MSIE") >0) {
       preg_match("/MSIE\s+([^;)]+)+/i", $sys,$ie);
        //$exp ="Internet Explorer ".$ie[1];
        $exp[0] ="Internet Explorer";
        $exp[1] =$ie[1];
    } elseif (stripos($sys, "Netscape")> 0) {
        $exp[0] ="Netscape";
        $exp[1] ="";
    } elseif (stripos($sys, "Opera") >0) {
        $exp[0] ="Opera";
        $exp[1] ="";
    } elseif (stripos($sys, "Chrome")> 0) {
        $exp[0] ="Chrome";
        $exp[1] ="";
    } else {
        $exp ="未知浏覽器";
        $exp[1] ="";
    }
    return $exp;
 }
 
//檢測浏覽器,如果為IE6及以下的,就跳轉頁面
 functioncheck_browser(){
    $ie_array = getBrowser();
    if($ie_array[0]=='Internet Explorer'&& $ie_array[1] <=6){
        include'./template/default/common/show_ie_out.htm';
       //header("Location:./template/default/common/show_ie_out.htm");
       exit();
    }
 }