<?php
 $bot[0] = "MSN";
$bots[0] = "MSNBOT/0.1 (http://search.msn.com/msnbot.htm)";
 $bot[1] = "google";
$bots[1] = "Googlebot/2.X (+http://www.googlebot.com/bot.html)";
// See http://www.robotstxt.org/wc/active/html/type.html for more Bots
$method = "log"; //mail or log
  //If     LOG
 $logfile="log.txt";
  //If     Mail
 $mail  = "you@mail.adres";
 
 $totalbots=count($bot) - 1;
for($i = 0;$i <= $totalbots;$i++){
    if (eregi($bot[$i], $_SERVER['HTTP_USER_AGENT'])){ 
            $onderwerp = $bot[$i]." Bezocht Uw Site."; 
             $msg = ucfirst($bot[$i])." heeft jou website bezocht!\n\n";      
             $msg .= "Bezocht op: " . date("d.m.Y H:i") . "\n\n";          
             $msg .= "Ip adres: " . $_SERVER['REMOTE_ADDR'] . "\n"; 
             $msg .= "Hostname: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n"; 
             $msg .= "LongName: " . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
            
        if($method=="log"){
             $msg .="--------------------------------------------------------------\n\n"; 
             $file = fopen($logfile,"a");
             $filec = fwrite($file,$msg);
             fclose($file);
             
            if(!$filec){
                $mailc = mail($mail, $onderwerp, $msg, "From: info@domein.nl"); 
            }
        }elseif($method=="mail"){
            $mailc = mail($mail, $onderwerp, $msg, "From: info@domein.nl");
            if($mailc == ""){
                 $msg .="--------------------------------------------------------------\n\n"; 
                $file = fopen($logfile,"a");
                fwrite($file,$msg);
                fclose($file);
            }
        }
    }
}
?>