萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php獲取IE浏覽器版本函數

php獲取IE浏覽器版本函數

在php中我們要獲取浏覽器信息可以直接使用$userAgent = strtolower($_SERVER[\"HTTP_USER_AGENT\"]);然後再判斷一下就可以判斷用戶浏覽器版本或型號了,希望下面的實例對大家有所幫助。

下面筆者為各位介紹一款如何判斷用戶浏覽器是不是IE6的php函數,如果是返回“真”,否則返回“假”。

 代碼如下 復制代碼

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 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";  
       } else {  
           $visitor_browser ="其它";  
        }  
           return $visitor_browser;  
       } 

copyright © 萬盛學電腦網 all rights reserved