browser: browsername (Opera, MSIE, NN, Moz) */
/* $browser->majorver: major version of browser */
/* $browser->minorver: minor version of browser */
/* List of UserAgents: http://www.psychedelix.com/agents.html */
/**************************************************************/
if ($browser=='[none]') $browser = strtolower(getenv("HTTP_USER_AGENT"));
else $browser = strtolower($browser);
//OPERA
if (preg_match("/.*opera[\/ ](\d{1,2})\.(\d{1,2}).*/",$browser,$match))
{
$this->browser = "Opera";
$this->majorver = $match[1];
$this->minorver = $match[2];
}
//MSIE
elseif (preg_match("/.*msie (\d{1,2})\.(\d{1,2}).*/",$browser,$match))
{
$this->browser = "MSIE";
$this->majorver = $match[1];
$this->minorver = $match[2];
}
//NETSCAPE 6+
elseif (preg_match("/mozilla\/\d\.\d.*netscape6?\/(\d)\.(\d).*/",$browser,$match))
{
$this->browser = "NN";
$this->majorver = $match[1];
$this->minorver = $match[2];
}
//MOZILLA
elseif (preg_match("/mozilla\/\d\.\d.*rv:(\d)\.(\d(\.\d)?).*gecko/",$browser,$match))
{
$this->browser = "Moz";
$this->majorver = $match[1];
$this->minorver = $match[2];
}
//NETSCAPE <4
elseif (preg_match("/mozilla\/(\d).(\d{1,2})/",$browser,$match))
{
$this->browser = "NN";
$this->majorver = $match[1];
$this->minorver = $match[2];
}
return $this;
} // end of function getbrowser()
#### DEMO ####
//Call GetBrowser-Function
$browser = getbrowser();
//Show Results
echo getenv("HTTP_USER_AGENT")."
";
echo $browser->browser."
";
echo $browser->majorver."
";
echo $browser->minorver."
";
?>