Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php : Finding Chrome and Safari Browsers

Tags:

php

user-agent

I use below code to find user agent,

    $user_agent = $_SERVER['HTTP_USER_AGENT']; 
    if (preg_match('/MSIE/i', $user_agent)) { 
       echo "Internet Explorer";
    }
    if (preg_match('/Firefox/i', $user_agent)) { 
       echo "FireFox";
    }
    if (strpos( $user_agent, 'Chrome') !== false)
    {
        echo "Google Chrome";
    }
    if (strpos( $user_agent, 'Safari') !== false)
    {
       echo "Safari";
    }
    if (preg_match('/Opera/i', $user_agent)) { 
       echo "Opera";
    }

    ?>

But my chrome browser returning below useragent suddenly

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.155 Safari/537.22

It contains the word safari and chrome.so both the browser names are printed.what is the solution for this.thanks.

like image 568
Vishnu Vishwa Avatar asked Mar 07 '13 13:03

Vishnu Vishwa


1 Answers

Try this :

$browser = get_browser(null, true);
print_r($browser);

From doc : Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the browscap.ini file.

ref: http://php.net/manual/en/function.get-browser.php

like image 196
Prasanth Bendra Avatar answered Sep 22 '22 07:09

Prasanth Bendra