Search code examples
phpgooglebot

Is it possible to find when google bot is crawling any urls on my site and record the last access time to a text file on server


Here's a code below which sends an email whenver any page is crawled by google and its resulting in spamming of mailbox. so is it possible to just record last crawled timestamp in a text file on server, which i can read later anytime using perl LWP mod. file should have just this data: 29,jan 2012 GMT etc If bot is visiting my site multiple times then it should overwrite txt file and record the last visit time only, please help with some implementation if possible

<?php
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )
{
// paste your email address here
$my_email = 'your_email_address@email.com';
// notify via email
mail($my_email,'[Notification]Googlebot Visit', 'Googlebot has just visited your      website WEBSITE_NAME: '.$_SERVER['REQUEST_URI']);
}
?>

I think we can do it by checking if google bot is hitting the server and what time it requested any page of site from server?


Solution

  • if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false ) {
        file_put_contents('somefile.txt', 'Googlebot was here - ' . date(DATE_RFC822));
    }