How to get user agent in php

User agent is a string that help us to identify the current browser. we can find the current browser name by using following code.

$myAgent = getUserAgent($_SERVER['HTTP_USER_AGENT']);

function getUserAgent($aUserAgent)
{
	$aBrowser = "";
	if (strpos($aUserAgent, 'Opera') || strpos($aUserAgent, 'OPR/'))
	{
		$aBrowser = 'Opera';
	}
	elseif(strpos($aUserAgent, 'Edge'))
	{
		$aBrowser = 'Edge';
	}
	elseif (strpos($aUserAgent, 'Chrome'))
	{
		$aBrowser = 'Chrome';
	}
	elseif (strpos($aUserAgent, 'Safari'))
	{
		$aBrowser = 'Safari';
	}
	elseif (strpos($aUserAgent, 'Firefox'))
	{
		$aBrowser = 'Firefox';
	}
	elseif (strpos($aUserAgent, 'MSIE'))
	{
		$aBrowser = 'Internet Explorer';
	}

	return $aBrowser;
}