in Technology

How to get an email whenever Google visits your site

I was reading the article – Ever wanted to know when google crawls your site via Digg. The article explains how you to send an email via a PHP Script when Google’s spider (GoogleBot) visits your site. So, why not automate that for each and every page that is PHP powered.

To include the script on every page of your site, let us follow the following steps;

1. Modify your .htaccess file (create if you do not have one) to use the auto_prepend_file feature, it should have this line

php_value auto_prepend_file /home/yourdomain.com/www/html/autoappend.php

(a single line full absolute path to the autoappend.php on your server)

2. Create/Modify your autoappend.php (you are free to change the file name accordingly here and in the .htaccess file) to include the PHP script from swik.net (I’ve modified it slightly to have a clickable url when you get the mail);

<?php
//let us notify someone when google crawls this page
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )
{
    // The email address we want to send the email to
    $email_address = '[email protected]';
     // Send the email
    mail($email_address,'Googlebot Visit', 'Googlebot has visited your page: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
}
?>

But, my files extension is not PHP even though my server support PHP, how do I use this?

Well, you can use the same .htaccess to enable PHP for any file extension, you have to add this line

AddType application/x-httpd-php .html .htm

This will parse all files with the extension html and htm as PHP scripts.

References

Update

  1. 2006 June 5 (10:00 am) – Be careful to set a filter for your email for this one. Now, I’m bombarded with “Googlebot Visit” mails!
  2. 2006 June 5 (02:00 pm) – This is perhaps a bad idea for a high traffic website. So, far I have received over 500 emails in just about 5 hours. I’m turning mine off.
  1. One thing to watch with this though is that lot's of spammers, particularly Comment spammers set 'Googlebot' to be the user agent so you'll get a lot of false positives from this I would have thought.

  2. One thing to watch with this though is that lot's of spammers, particularly Comment spammers set 'Googlebot' to be the user agent so you'll get a lot of false positives from this I would have thought.

Comments are closed.