PHP: How to detect the browser currently used by the user?

Chrome
if (stripos($_SERVER['HTTP_USER_AGENT'],"Chrome"))
        $browser = 'Chrome';
Firefox
if (stripos($_SERVER['HTTP_USER_AGENT'],"Firefox"))
        $browser = 'Firefox';
Safari
if (stripos($_SERVER['HTTP_USER_AGENT'],"Safari"))
        $browser = 'Safari';