Hi,
To detect the name of visitor's web browser, you can the use the function below. At first, it collects the general informations via $_SERVER['HTTP_USER_AGENT']. Then it search for a specific browser name. If there is a match, it will return browser name.
function getBrowser() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$browser = "N/A";
$browsers = array(
'/msie/i' => 'Internet explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/edge/i' => 'Edge',
'/opera/i' => 'Opera',
'/mobile/i' => 'Mobile browser'
);
foreach ($browsers as $regex => $value) {
if (preg_match($regex, $user_agent)) { $browser = $value; }
}
return $browser;
}
echo "Browser: " . getBrowser();