Identify OS from user agent string
I'm trying to come up with a quick and dirty way to identify OS by regexing the user agent string. I'm only interested in Windows (with version), Mac, or Linux - anything else is unknown. In anyone can sanity check my regex or offer any pointers on parsing user agent strings that would be much appreciated. thanks in advance.
PHP Code:
if (eregi("(win.*NT 5.1|win.*NT 5.1|Windows XP)", $agent))
{
$visos = "Windows XP";
}
elseif (eregi("(win.*NT 5.0)", $agent))
{
$visos = "Windows 2000";
}
elseif (eregi("(win.*NT 5.2)", $agent))
{
$visos = "Windows Server";
}
elseif (eregi("win.*NT)", $agent))
{
$visos = "Windows NT";
}
elseif (eregi("(win.*98)", $agent))
{
$visos = "Windows 98";
}
elseif (eregi("(win 9x.*4.90)", $agent))
{
$visos="Windows ME";
}
elseif (eregi("win.*95)", $agent))
{
$visos = "Windows 95";
}
elseif ((ereg("(Mac|PPC|Mac_PowerPC)", $agent))
{
$visos = "Mac";
}
elseif (eregi("Linux", $agent))
{
$visos = "Linux";
}
else
{
$visos = "unknown";
}