note 57779 deleted from function.get-browser by bjori
| From: | bjori@php.net | Date: | Mon, 09 Oct 2006 10:59:48 +0000 |
| Subject: | note 57779 deleted from function.get-browser by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118256@lists.php.net to get a copy of this message | ||
Note Submitter: matt at axia dot org dot uk
----
This is a fix for a bug in the code left by steve (in Feb). Basically, if the search for the
browser type was at the beginning of the 'HTTP_USER_AGENT' (ie. the first character) then
strpos returns 0 causing, the code to drop out incorrectly. I also trimmed the code to make it more
efficient.
function _get_browser()
{
$browser = array (
"MSIE", // parent
"OPERA",
"MOZILLA", // parent
"NETSCAPE",
"FIREFOX",
"SAFARI"
);
$info[browser] = "OTHER";
foreach ($browser as $parent)
{
if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
{
$f = $s + strlen($parent);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
$version = preg_replace('/[^0-9,.]/','',$version);
$info[browser] = $parent;
$info[version] = $version;
}
}
return $info;
}