I use:
<?php
$agent = $_SERVER["HTTP_USER_AGENT"];
if( preg_match('/MSIE (\d+\.\d+);/', $agent) ) {
echo "You're using Internet Explorer";
} else if (preg_match('/Chrome[\/\s](\d+\.\d+)/', $agent) ) {
echo "You're using Chrome";
} else if (preg_match('/Edge\/\d+/', $agent) ) {
echo "You're using Edge";
} else if ( preg_match('/Firefox[\/\s](\d+\.\d+)/', $agent) ) {
echo "You're using Firefox";
} else if ( preg_match('/OPR[\/\s](\d+\.\d+)/', $agent) ) {
echo "You're using Opera";
} else if (preg_match('/Safari[\/\s](\d+\.\d+)/', $agent) ) {
echo "You're using Safari";
}