欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

获取用户的浏览器以及版本信息

程序员文章站 2022-05-24 17:05:57
...
function determinebrowser () {
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '' ;
$browseragent = "";   //浏览器
$browserversion = ""; //浏览器的版本
if (preg_match('/360SE/i',$agent)) {
$browserversion = '';
$browseragent = "360浏览器";
    } else if(preg_match('/Maxthon (([0-9_.]{1,2}+))/i',$agent,$version)){
$browserversion = $version[1];
$browseragent = "Maxthon";
    }else if (preg_match('/MSIE (([0-9_.]{1,2})+)/i',$agent,$version)) {
$browserversion = $version[1];
$browseragent = "Internet Explorer";
    } else if (preg_match( '/iOpera\/(([0-9_.]{1,2})+)/i',$agent,$version)) {
$browserversion = $version[1];
$browseragent = "Opera";
    } else if (preg_match( '/Firefox\/(([0-9_.]{1,3})+)/i',$agent,$version)) {
$browserversion=$version[1];
$browseragent = "Firefox";
    } else if (preg_match( '/Chrome\/(([0-9_.]{1,5})+)/i',$agent,$version)) {
$browserversion = $version[1];
$browseragent = "Chrome";
    } else if (preg_match( '/Safari\/(([0-9_.]{1,5})+)/',$agent,$version)) {
$browserversion = $version[1];
$browseragent = "Safari";
    } else {
$browserversion = "";
$browseragent = "Unknown";
    }
return $browseragent." ".$browserversion;
}

以上就介绍了获取用户的浏览器以及版本信息,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。