Browser name detection only:
<?php
/*
Browser Name detection
By Geoffrey Sneddon, with some help from Clayton Smith
Released under the zlib/libpng license
*/
function browser($ua)
{
if (preg_match('/bot/i', $ua) || preg_match('/crawl/i', $ua) || preg_match('/yahoo\!/i', $ua))
{
return 'Bot';
}
elseif (preg_match('/opera/i', $ua))
{
return 'Opera';
}
elseif (preg_match('/msie/i', $ua))
{
return 'Internet Explorer';
}
elseif (preg_match('/omniweb/i', $ua))
{
return 'OmniWeb';
}
elseif (preg_match('/icab/i', $ua))
{
return 'iCab';
}
elseif (preg_match('/safari/i', $ua))
{
return 'Safari';
}
elseif (preg_match('/konqueror/i', $ua))
{
return 'Konqueror';
}
elseif (preg_match('/Flock/i', $ua))
{
return 'Flock';
}
elseif (preg_match('/firebird/i', $ua))
{
return 'Firebird';
}
elseif (preg_match('/phoenix/i', $ua))
{
return 'Phoenix';
}
elseif (preg_match('/firefox/i', $ua))
{
return 'Firefox';
}
elseif (preg_match('/chimera/i', $ua))
{
return 'Chimera';
}
elseif (preg_match('/camino/i', $ua))
{
return 'Camino';
}
elseif (preg_match('/seamonkey/i', $ua))
{
return 'SeaMonkey';
}
elseif (preg_match('/galeon/i', $ua))
{
return 'Galeon';
}
elseif (preg_match('/epiphany/i', $ua))
{
return 'Epiphany';
}
elseif (preg_match('/mozilla\/5/i', $ua) || preg_match('/gecko/i', $ua))
{
return 'Mozilla';
}
elseif (preg_match('/mozilla\/4/i', $ua))
{
return 'Netscape';
}
elseif (preg_match('/lynx/i', $ua))
{
return 'Lynx';
}
elseif (preg_match('/links/i', $ua))
{
return 'Links';
}
elseif (preg_match('/curl/i', $ua))
{
return 'cURL';
}
elseif (preg_match('/wget/i', $ua))
{
return 'Wget';
}
else
{
return 'Unknown';
}
}
?>
Grabbed straight out Fstats source. Like the rest of the Fstats, released under the zlib/libpng license:
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Example:
<?php
if (browser($_SERVER['HTTP_USER_AGENT']) == 'Internet Explorer')
echo 'You are using Internet Explorer.';
?>