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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With