Kapan bot/spider mengunjungi situs anda?


Status
Not open for further replies.

Optinux

(Ret) Community Leader
Kadang penasaran rasanya, apakah halaman2 web kita telah dikunjungi oleh robot/crawler/spider dari berbagai search engine?
Bila anda ingin mengetahuinya, berikut ada contoh sederhana untuk mengirimkan email ke mailbox anda setiap ada kunjungan dari search engine.
Mudah2an bermanfaat.

Deteksi IP:
PHP:
<?php
/* Letakkan kode ini dalam script anda */

$my_email = '[email protected]';
$to_email = '[email protected]';

$ip = $_SERVER['REMOTE_ADDR'];

/* IP range berikut hanya sebahagian dari IP Google, Inktomi/Yahoo, dan MSN */
$robot_ip_range = '^64\.68\.8[0-7]|^66\.249\.(6[4-9]|9[0-5])|^216\.239\.(3[2-9]|6[0-3])|'.
                  '^66\.196\.(6[4-9]|[7-9][0-9]|1[0-2][0-7])|^68\.142\.(19[2-9]|2[0-5][0-5])|'.
                  '^65\.(5[2-5])|^207\.68\.(12[8-9]|1[3-9][0-9]|20[0-7])';

if ( preg_match("/$robot_ip_range/i",$ua) ) {
  $filename = $_SERVER['PHP_SELF'];
  $subject = 'Robot was here...';
  $mail_body = "Robot was here...\n".
                        "Filename: $filename\n".
                        "From IP: $ip\n";
  $headers = "From: $my_email\n".
                     "X-Mailer: PHP\n";
  mail($to_email, $subject, $mail_body, $headers);
}

echo 'Done...!';
?>

Deteksi UserAgent:
PHP:
<?php
/* Letakkan kode ini dalam script anda */

$my_email = '[email protected]';
$to_email = '[email protected]';

$ua = $_SERVER['HTTP_USER_AGENT'];

$robot_list = 'Googlebot|Yahoo|msnbot|Inktomi|Slurp|Gigabot|FAST|Jeeves|Teoma|Webcrawler|Scooter'.
              '|Robozilla|ia_archive|Scrubby|wisenutbot|zyborg|Baiduspider|Crawl|Robot|Spider|Archive|Snapbot';

if ( preg_match("/$robot_list/i",$ua) ) {
  $filename = $_SERVER['PHP_SELF'];
  $subject = 'Robot was here...';
  $mail_body = "Robot was here...\n".
                        "Filename: $filename\n".
                        "Useragent: $ua\n";
  $headers = "From: $my_email\n".
                     "X-Mailer: PHP\n";
  mail($to_email, $subject, $mail_body, $headers);
}

echo 'Done...!';
?>
 

ruangweb

(Ret) Community Leader
sebenernya juga bisa diliat di statistik spt webalizer, awstat atau googleanalytics.

ribet juga kalo situs kita adalah situs populer yg rajin dikunjungin bot, tiap kali bot masuk ngirim email
 
Status
Not open for further replies.

    
Top