How to get browserName in PHP

function getBrowser() {

global $user_agent;

$browser_array  =   array(
‘/msie/i’       =>  ‘Internet Explorer‘,
‘/firefox/i’    =>  ‘Firefox’,
‘/safari/i’     =>  ‘Safari’,
‘/chrome/i’     =>  ‘Chrome’,
‘/opera/i’      =>  ‘Opera’,
‘/netscape/i’   =>  ‘Netscape’,
‘/maxthon/i’    =>  ‘Maxthon’,
‘/konqueror/i’  =>  ‘Konqueror’,
‘/mobile/i’     =>  ‘Handheld Browser’
);

foreach ($browser_array as $regex => $value) { 

if (preg_match($regex, $user_agent)) {
$browser    =   $value;
}

}
$browser        =  $browser ? $browser : “Unknown Browser”;
return $browser;

}

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website