getBrowser PHP 5.3 compatible (include Opera fix)
Posted: Tue Apr 13, 2010 1:45 am
Code: Select all
function getBrowser( &$browser, &$version )
{
if ( version_compare( phpversion(), "4.1.0", "<") )
{
global $_SERVER;
}
if (preg_match( '#MSIE ([0-9]\.[0-9]{1,2})#',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'ie';
}
elseif (preg_match( '#Safari/([0-9\.]+)#',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'safari';
}
elseif (preg_match( '#Konqueror/([0-9\.\-rc]+)#',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'konqueror';
}
elseif (preg_match( '#Opera/([0-9]\.[0-9]{1,2})#',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'opera';
}
elseif (preg_match( '#Mozilla/([0-9]\.[0-9]{1,2})#',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'mozilla';
}
else
{
$version = 0;
$browser = 'unknown';
}
}