PHP获取访客浏览器名称的方法

PHP 2012-11-18

分享一个PHP获得访客浏览器名称的方法,可以得到的浏览器有IE内核的Maxthon、Maxthon2.0、Maxthon、IE10、IE9、IE8、IE7、IE6、IE5.5、IE4.01、NetCaptor、Netscape、谷歌Chrome、Lynx、Opera、Konqueror、Mozilla、Firefox。没有在这些在内的就以其他标注。如果是实际使用中用不到这么细,可以自行删除某些elseif,如果还有其他型号的就自行获得User_agent然后分析添加elseif。

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 10.0")) {   
    	$visitor_browser ="MSIE 10.0";   
    }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;   
}

本文由 Jazzy 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论