Return to Snippet

Revision: 45909
at May 11, 2011 00:21 by talcual


Initial Code
<?php 

$robot[] = "googlebot";   
$robot[] = "google";  
$robot[] = "mediapartners";  
$robot[] = "msnbot";   
$robot[] = "msn";  
$robot[] = "overture";   
$robot[] = "lycos";   
$robot[] = "seek";   
$robot[] = "inktomi";   
$robot[] = "yahoo";   
$robot[] = "slurp";  
$robot[] = "altavista";   
$robot[] = "alexa";   
$robot[] = "crawler";   
$isRobot=false; 
   
foreach($robot as $bot){  
   $str = strtolower($_SERVER['HTTP_USER_AGENT']);  
   if (strpos($str, $bot) !== false ){  
       $isRobot=true;   
       break;   
    }   
}   


//visitas  
if($isRobot){  
   
  //// Esta parte es Opcional 
   $heads = "MIME-Version: 1.0 rn";  
   $heads .= "Content-type: text/html; charset=utf-8 rn";  
     
   $body ="<b>Robot Name:</b> ".$str."<br>";  
   $body .="<b>Robot Address:</b> ".$_SERVER['REMOTE_ADDR'];  
     
   mail(mimail, "Detected Bot", $body, $heads);  
 //// Fin de la Parte Opcional 

}else{  
   $vql= "UPDATE bg_articulos SET visitas=visitas+1 WHERE art_id='".$artid."'"; 
   mysql_query($vql);  
} 

?>

Initial URL
http://www.codigolandia.com/art-Detector+de+Bots,+Spider+y+Crawlers-php-114.tc

Initial Description
This Snnipet detect the querys generated by a bot, crawler or spider.
Este Snnipet detecta las peticiones generadas por los bots, Spiders y Crawlers.

Initial Title
Detect Bot's, Crawlers and Spiders with PHP ( Spanish )

Initial Tags


Initial Language
PHP