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

前提是你 提交于 2019-12-22 08:18:15

问题


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?


回答1:


if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false ) {
    file_put_contents('somefile.txt', 'Googlebot was here - ' . date(DATE_RFC822));
}
  • http://php.net/manual/en/function.file-put-contents.php
  • http://www.php.net/manual/en/function.date.php


来源:https://stackoverflow.com/questions/9048531/is-it-possible-to-find-when-google-bot-is-crawling-any-urls-on-my-site-and-recor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!