I use below code to find user agent,
$user_agent = $_SERVER[\'HTTP_USER_AGENT\'];
if (preg_match(\'/MSIE/i\', $user_agent)) {
echo \"Internet
Chrome's user agent contains Safari
but Safari's user agent doesn't contain Chrome
so use if ... elseif
:
if (stripos( $user_agent, 'Chrome') !== false)
{
echo "Google Chrome";
}
elseif (stripos( $user_agent, 'Safari') !== false)
{
echo "Safari";
}
Note: use stripos
instead of strpos
to account for case-variations.