I can't get visitors browser

Hello,
I use wamp as localhost.
I have Chrome , firefox. OPera and internet explorer installed on my PC

I found code examples for detecting visitor browser

Here are 2 options:

//  Get user OS and browser

////     1     //////

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser();
print_r($browser);
//   https://www.youtube.com/watch?v=PgJ8jHARmCk
/////     2    / ////
$u_agrent = $_SERVER['HTTP_USER_AGENT'];
$ub = "";

if(preg_match('/MSIE/i', $u_agrent)){
    $ub = "explorer";
} elseif(preg_match('/firefox/i', $u_agrent)){
    $ub = "firefox";
} elseif(preg_match('/safari/i', $u_agrent)){
    $ub = "safari";
} elseif(preg_match('/Chrome/i', $u_agrent)){
    $ub = "Chrome";
} elseif(preg_match('/flock/i', $u_agrent)){
    $ub = "";
} elseif(preg_match('/opera/i', $u_agrent)){
    $ub = "opera";
} else {
    $ub = "OTHER / UNKNOWN";
}

echo "<br>your browser :".$ub;

When I ron the code the output says that I use safari

How can that be ? I never had it on my PC

P.S. my default browser is Opera how do I change default browser ?

Off Topic

Go to the browser you want to use, open “preferences” and there will be a check-box to set it as the default browser.

That’s because most Chrome-based user agents contain the string “Safari”.

Opera seems to contain the string “OPR” rather than “Opera” these days.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.