get_browser() returns Chrome when using Opera browser in Samsung galaxy tab

264 Views Asked by At

Hi Im tracking the browsers of the users who are visiting my site with the use of browsecap.ini

the following is the code that i use

if(isset($message['HTTP_USER_AGENT'])){
    $get_browser = get_browser($message['HTTP_USER_AGENT'], true);
       if (!empty($get_browser)){
           $str_values.='".mysql_real_escape_string($get_browser['comment'])."'

But when the users who use the opera browser in a galaxy tab are shown as chrome browser users

can anybody help me to rectify this isse

P.S - Im using the lite version of browsecap.ini file

1

There are 1 best solutions below

0
Drakes On

You kindly provided me with a sample UA string of the offending mobile Opera browser:

Mozilla/5.0 (Linux; Android 4.1.2; GT-P3100 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.81 Safari/537.36 OPR/28.0.1764.90386

and the regex returned by get_browser() on that UA is:

$^mozilla/5.0 (.*linux.android.4.1.) applewebkit/.* (khtml, like gecko).*chrome/41..safari/.$

which didn't detect the Opera browser at all. However, I found this function that you can also run to get the browser name. The very first check is for that "OPR/" fragment of the UA string.

When run with the test UA supplied above, the output is "Opera".

<?php
function ExactBrowserName() {
    $ExactBrowserNameUA=$_SERVER['HTTP_USER_AGENT'];

    If (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "opr/")) {
        // OPERA
        $ExactBrowserNameBR="Opera";
    } ElseIf (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "chrome/")) {
        // CHROME
        $ExactBrowserNameBR="Chrome";
    } ElseIf (strpos(strtolower($ExactBrowserNameUA), "msie")) {
        // INTERNET EXPLORER
        $ExactBrowserNameBR="Internet Explorer";
    } ElseIf (strpos(strtolower($ExactBrowserNameUA), "firefox/")) {
        // FIREFOX
        $ExactBrowserNameBR="Firefox";
    } ElseIf (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "opr/")==false and strpos(strtolower($ExactBrowserNameUA), "chrome/")==false) {
        // SAFARI
        $ExactBrowserNameBR="Safari";
    } Else {
        // OUT OF DATA
        $ExactBrowserNameBR="OUT OF DATA";
    };

    return $ExactBrowserNameBR;
}
?>

Ref: How to get exact browser name and version?