The example in this article describes how to obtain the user's browser version in PHP. Share it with everyone for your reference. The specific analysis is as follows:
In php, we have a global variable $_SERVER['HTTP_USER_AGENT']; which can obtain all the user's information. We need to process it before we can determine the type of user's browser. The following function can accurately browse the user's information. Server version code.
function getbrowse()
{
$agent = $_server['http_user_agent'];
$browser = '';
$browserver = '';
$browser = array('lynx', 'mosaic', 'aol', 'opera', 'java', 'macweb', 'webexplorer', 'omniweb');
for($i = 0; $i <= 7; $i ){
if(strpos($agent, $browsers[$i])){
$browser = $browsers[$i];
$browserver = '';
}
}
if(ereg('mozilla', $agent) && !ereg('msie', $agent)){
$temp = explode('(', $agent);
$part = $temp[0];
$temp = explode('/', $part);
$browserver = $temp[1];
$temp = explode(' ', $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;
}
//Application method
//in ie
echo getbrowse(); //internet explorer 6.0
//In firefox
echo getbrowse() ;//netscape navigator 5.0
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/975890.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975890.htmlTechArticleHow to get the user browser version in php. This article mainly introduces the method of getting the user browser version in php. Using $_SERVER['HTTP_USER_AGENT'] to obtain user information is a very practical technique...