How to check Client browser using PHP

Here is the simple function to display working browser in PHP

$user_agent = $_SERVER['HTTP_USER_AGENT'];

function getBrowser() {
global $user_agent;
$browser = "Unknown Browser";
$browser_array = array(
 '/msie/i' => 'Internet Explorer',
 '/firefox/i' => 'Firefox',
 '/safari/i' => 'Safari',
 '/chrome/i' => 'Chrome',
 '/edge/i' => 'Edge',
 '/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;
return $browser;
}

$user_browser   = getBrowser();
if($user_browser == 'Safari')
{
echo "Safari";
}

My Thought

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

Our Tool : hike percentage calculator