How to detect in PHP what web browser are visitors using ?

Can you please give me suggestion, how to detect the name of web browser, that is used by visitors ? I need to use this function in PHP.
posted on 27.07.2019 at 18:10
0pnshow more

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();
posted on 04.08.2019 at 19:52
0pnshow more
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.