static $userAgent = '';
static function getUserAgent()
{
$header = getallheaders();
self :: $userAgent = $header['User-Agent'];
}
function findUserAgentByKey($ua, $key)
{
$len = strlen($key);
$start = strpos($ua, $key);
$pos = strpos($ua, ' ', $start + $len + 1);
return substr($ua, $start + $len, $pos - $len - $start);
}
static function detectUserAgent()
{
self :: getUserAgent();
if (strpos(self :: $userAgent, 'MSIE') != null)
{
self :: $version[] = IE;
self :: $version[] =self:: findUserAgentByKey(self :: $ userAgent, 'MSIE');
}
else if (strpos(self :: $userAgent, 'Gecko/') != null)
{
self :: $version[] = self :: $version [] =self:: findUserAgentByKey(self :: $userAgent, 'Firefox/');
}
else if (strpos(self :: $userAgent, 'AppleWebKit/') != null)
{
self :: $ version[] = CHROME;
self :: $version[] = self:: findUserAgentByKey(self :: $userAgent, 'Chrome/');
}
else if (strpos(self :: $userAgent, 'Presto/' ) != null)
{
self :: $version[] = OPERA;
self :: $version[] = self:: findUserAgentByKey(self :: $userAgent, 'Opera/');
} else
{
}
}
function matchUserAgent($ua, $key)
{
preg_match("/$key.([^s]*?)s/", $ua, $out);
}
}
$ua=UserAgentDetect::detectUserAgent();