mo Posted July 14, 2009 Share Posted July 14, 2009 Hello, I read through the forum for an answer but the one post that almost answered it, did not leave the solution, just a solved message. I use the following to get the browser but do not have an easy to get the version number. Any help will be appreciated. function determine_browser() { $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); // Identify the browser. Check Opera and Safari first in case of spoof. Let Google Chrome be identified as Safari. if (preg_match('/opera/', $userAgent)) { $name = 'OPERA'; } elseif (preg_match('/webkit/', $userAgent)) { $name = 'SAFARI'; } elseif (preg_match('/msie/', $userAgent)) { $name = 'IE'; } elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) { $name = 'FIREFOX'; } else { $name = 'UNKNOWN'; } return $name; } Link to comment https://forums.phpfreaks.com/topic/165972-clean-way-to-get-browser-version/ Share on other sites More sharing options...
rhodesa Posted July 14, 2009 Share Posted July 14, 2009 Check out http://www.phpfreaks.com/forums/index.php/topic,226197.0.html Link to comment https://forums.phpfreaks.com/topic/165972-clean-way-to-get-browser-version/#findComment-875370 Share on other sites More sharing options...
mo Posted July 14, 2009 Author Share Posted July 14, 2009 Check out http://www.phpfreaks.com/forums/index.php/topic,226197.0.html Check out http://www.phpfreaks.com/forums/index.php/topic,226197.0.html Thanks, however I am on a shared host and cannot install anything on the server. Link to comment https://forums.phpfreaks.com/topic/165972-clean-way-to-get-browser-version/#findComment-875372 Share on other sites More sharing options...
mattal999 Posted July 14, 2009 Share Posted July 14, 2009 Try this: <?php /* get_browser_ This function determines visitor browser. */ function get_browser_($user_agent) { $browsers = array( 'Opera' => 'Opera', 'Mozilla Firefox'=> '(Firebird)|(Firefox)', 'Galeon' => 'Galeon', 'Mozilla'=>'Gecko', 'MyIE'=>'MyIE', 'Lynx' => 'Lynx', 'Netscape' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)', 'Konqueror'=>'Konqueror', 'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)', 'Internet Explorer 6' => '(MSIE 6\.[0-9]+)', 'Internet Explorer 5' => '(MSIE 5\.[0-9]+)', 'Internet Explorer 4' => '(MSIE 4\.[0-9]+)', ); foreach($browsers as $browser=>$pattern) { if (eregi($pattern, $user_agent)) return $browser; } return 'Unknown'; } ?> Link to comment https://forums.phpfreaks.com/topic/165972-clean-way-to-get-browser-version/#findComment-875376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.