Forum Moderators: coopster
So, I was looking for a small function (and not a huge class) that can detect Opera, Firefox and IE7. I found one but it is not working for Opera. Usually, I am able to solve PHP problems myself, but this time I have failed... I am completely lost with those string functions...
function browser_info() {
$browser = array ("MSIE", "OPERA", "MOZILLA", "NETSCAPE", "FIREFOX", "SAFARI");
$info['browser'] = "OTHER";
foreach ($browser as $parent) {
$s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
$f = $s + strlen($parent);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
$version = preg_replace('/[^0-9,.]/','',$version);
if (strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) {
$info['browser'] = $parent;
$info['version'] = $version;
}
}
return $info;
}
Anyway, using Firefox, print_r($info) returns Array ( [browser] => FIREFOX [version] => 2.0. ) but using Opera, it returns Array ( [browser] => OTHER ) instead of OPERA + VERSION...
Any idea what's wrong with the above function?
Or any links/resources (in PM please) for a similar functions?
Thanks
Having my Opera detect as IE or Firefox, your script worked perfectly
Having my Opera detect as Opera, your script gave me the "Other" choise
echoing my $_SERVER['HTTP_USER_AGENT'] i got: Opera/9.21 (Windows NT 5.1; U; en)
Your script should work, but i cant find any flaws... strange. Sorry i couldt help
I did exactly the same than what you did... This script works perfectly for Firefox and Internet Explorer AND it was also working with previous version of Opera 8.
But from Opera 9.21, it doesn't work...
Very strange indeed knowing that HTTP_USER_AGENT is a plain "Opera/9.21" (no funny characters).
Your script should work, but i cant find any flaws... strange. Sorry i couldt help
if (strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) { if (strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent) !== false) {