Home >Backend Development >PHP Tutorial >php Get user browser version code_PHP tutorial
php gets the user browser version code. In php, we have a global variable $_SERVER['HTTP_USER_AGENT']; which can get all the user's information. We need to process it to determine what type of user's browser it is. The following function can be used The exact user browser version number code.
php tutorial to get the user browser version code
In php we have a global variable $_server['http_user_agent']; which can get all the user's information. We need to process it to determine what type of user browser it is. Yes, the following function can accurately determine the user browser version number code.
function getbrowse()
$browserver = '';
browser = array('lynx', 'mosaic', 'aol', 'opera', 'java', 'macweb', 'webexplorer', 'omniweb');
for($i = 0; $i < ;= 7; $i ++){
$browserver = '' ;
}
}
if(ereg('mozilla', $agent) && !ereg('msie', $agent)){
$temp = explode('(', $agent );
$part = $temp[0];
$temp = explode('/', $part);
$browserver = $temp[1];
' ', $browserver);
$browserver = $temp[0];
$browserver = preg_replace('/([d.]+)/', '1', $browserver);
$browserver = $browserver;
$browser = 'netscape navigator';
}
if(ereg('mozilla', $agent) && ereg('opera', $agent)) {
$temp = explode('(', $agent);
$part = $temp[1];
$temp = explode(')', $part);
$browserver = $temp[ 1];
$temp = explode(' ', $browserver);
$browserver = $temp[2];
$browserver = preg_replace('/([d.]+)/', '1', $browserver);
$browserver = $browserver;
$browser = 'opera';
}
if(ereg('mozilla', $agent) && ereg('msie', $agent)){
$temp = explode('(', $agent);
$part = $temp[1];
$temp = explode(';', $part);
$part = $temp[1];
$temp = explode(' ', $part);
$browserver = $temp[2];
$browserver = preg_replace('/([d.]+)/','1',$browserver);
$browserver = $browserver;
$browser = 'internet explorer';
}
if($browser != ''){
$browseinfo = $browser.' '.$browserver;
} else {
$browseinfo = false;
}
return $browseinfo;
}
//应用方法
//在ie中
echo getbrowse(); //internet explorer 6.0
//在firefox中
echo getbrowse() ;//netscape navigator 5.0