alternative to get_browser?

httpbrowsercapabilities, php

Solution

This is the way I do it : I have included the most common browers out there.

<?php

function get_browsername() {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE){
$browser = 'Microsoft Internet Explorer';
}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {
$browser = 'Google Chrome';
}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE) {
$browser = 'Mozilla Firefox';
}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) {
$browser = 'Opera';
}elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {
$browser = 'Apple Safari';
}else {
$browser = 'error'; //<-- Browser not found.
}
return $browser;
}

echo 'Browser is '. get_browsername(); //<-- Display the browser name

if(get_browsername() == 'Google Chrome') { 
// Use the function to check
}

Hope This helps.

Problem

I have been using php's `get_browser()` function to do some light analytics of my users, mostly for debugging. However, it seems that the maintainer for browsercap.ini, the data that powers get_browser has quit the project, and while some folks seem to be working on restarting it, the data is getting very stale. They are talking about a total rewrite, and so I am afraid that it will take quite a while before it gets going again. Does anybody know an alternative that does not rely on browsercap.ini? Edit: I am sorry for the ambiguity in my question. I need this for debugging, not analytics. I am using it in a "report bug" tool in a web application that has a lot of cross-browser bugs, but I have no control over the client machines. It is a very old application (originally built for IE6) and we have been doing our best to bring it up to date, but the cross-browser issues are at times very hard to find. Thank you again

Original source