Very simple function analyze $_SERVER['HTTP_USER_AGENT'] variable and looking for crawler signature. If function founds crawler, it will return it's name, otherwise - false.
function crawlerDetect($USER_AGENT)
{
$crawlers = array(array('Google', 'Google'),array('msnbot', 'MSN'),array('Rambler', 'Rambler'),array('Yahoo', 'Yahoo'), array('AbachoBOT', 'AbachoBOT'),array('accoona', 'Accoona'),array('AcoiRobot', 'AcoiRobot'),array('ASPSeek', 'ASPSeek'), array('CrocCrawler', 'CrocCrawler'),array('Dumbot', 'Dumbot'),array('FAST-WebCrawler', 'FAST-WebCrawler'),array('GeonaBot', 'GeonaBot'),array('Gigabot', 'Gigabot'),array('Lycos', 'Lycos spider'),array('MSRBOT', 'MSRBOT'),array('Scooter', 'Altavista robot'),array('AltaVista', 'Altavista robot'),array('IDBot', 'ID-Search Bot'),array('eStyle', 'eStyle Bot'),array('Scrubby', 'Scrubby robot'));
foreach ($crawlers as $c)
{
if (stristr($USER_AGENT, $c[0]))
{
return($c[1]);
}
}
return false;
}
// example
$crawler = crawlerDetect($_SERVER['HTTP_USER_AGENT']);
if ($crawler )
{
// it is crawler, it's name in $crawler variable
}
else
{
// usual visitor
}