PHP: Be Notified When Google Crawls Your Site
Please subscribe to ProTycoon.com via the RSS Feed or Via Email.
Have you ever wanted to know when Google crawls your website? Well now you can using a simple PHP script which emails you everytime GoogleBot crawls your site.
I thought that many of you might find this bit of code useful, that is why I have decided to post it up.
It is not a very long piece of code, but I will talk you through how it functions.
First off lets take a look at the code:
<?php
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )
{
// Your email address
$email_address = 'you@yourdomain.com';
// Send yourself an email
mail($email_address,'Googlebot Alert', 'The Googlebot has visited your page: '.$_SERVER['REQUEST_URI']);
}
?>
As you can see it is a simple piece of code.
First of all it checks the user agent to see if it is ‘Googlebot’. If the user agent is ‘Googlebot’ then it will send an email to the email address you supply.
If you have any comments or problems with this code, feel free to post them below.










Tom | February 20th, 2008 at 12:01 pm #
Hey, I know this probably sounds really stupid but, where do you insert this code?
David Shaw | February 20th, 2008 at 6:10 pm #
I would recommend adding it to the bottom of your pages! Just before the tag, as this will help to reduce page loading times, by letting your main content load first.
Hope that helps
Recibe un email cuando Google visite tu pagina | RFD Internet | June 3rd, 2008 at 11:22 am #
[...] ProTycoon han publicado un sencillo script en PHP con el que puedes conseguir que te llegue un email cada vez [...]
meneame.net | June 3rd, 2008 at 2:36 pm #
Recibe un email cada vez que Crawls de Google visite tu pagina (EN)…
Código PHP que al introducirlo en la página a rastrear, manda un mail cada vez que googlebot ingresa a la misma, os dejo aquà la traducción…
Rithish | June 4th, 2008 at 6:45 am #
It would do good if you create a file and insert this code into it. Then include this file within all files you think that are seachable.
David Shaw | June 4th, 2008 at 3:55 pm #
That is the best way to use this code.
Thomas Schaaf | June 8th, 2008 at 1:53 pm #
You would get spammed.. my sites get crawled VERY often.. and I know a lot of people who set google as their browsers “name” so they can access more information on pay per view sites.
But I guess if you have a small site its good
vince | June 8th, 2008 at 5:42 pm #
I put this code on my home page (index.html) but doesn’t parse…I get a blank page with this message:
Parse error: syntax error, unexpected ‘@’ in /home….
I usually don’t have any probs inserting php code in my html pages…
Any suggestion to make this code work?
Greeny | June 9th, 2008 at 6:41 pm #
Thanks, i’ll go test it
Recibe un mail cada vez que Google visite tu blog | El rincón del bit | June 16th, 2008 at 8:41 pm #
[...] script, procede de protycoon. No se ha necesitado mucho código para implementarlo. PLAIN TEXT [...]
Recibe un aviso por email cada vez que el Google Bot visite tu blog | June 22nd, 2008 at 6:21 am #
[...] Lee Mi Blog y Protycoon. Archivado en Miniblog, Programación Deja aquà tu comentario ↓ Etiquetas google, [...]
Aggressive | June 22nd, 2008 at 6:59 pm #
i hope google people dont mind if we use this code lolx..
David Shaw | June 23rd, 2008 at 6:44 am #
There is no problems with Google for using this code!
Max | June 23rd, 2008 at 11:28 am #
You need to insert that code inside a .php file rather than .html.
PHP will not be parsed as php while inside a html page unless you change your server to parse html files as php
hope that makes sense
Vahur | July 11th, 2008 at 2:12 pm #
Performance, performance, performance!
Sending one mail takes in my server about 0.03 seconds, thats asmuch as generating my whole page with custom content.
But if performance is not so important and you dont have hundreds of pages, then go for it.
Recibe un aviso por email cada vez que el Google Bot visite tu blog « El Cubanito Web | July 30th, 2008 at 6:27 pm #
[...] VÃa: Lee Mi Blog y Protycoon. [...]
Joe | August 23rd, 2008 at 11:10 pm #
Why would you use the condition “if(strpos($_SERVER['HTTP_USER_AGENT'],’Googlebot’) !== false)” as opposed to “if(strpos($_SERVER['HTTP_USER_AGENT'],’Googlebot’))”? Logically it would be the same, right?
vahur | August 24th, 2008 at 3:31 pm #
When user agent starts with “googlebot” then strpos() returns integer 0, what will be boolean false. If !== false is used then integer 0 changes to true.
Pereyrada » Notificar cuando el Bot de Google nos visita. | September 25th, 2008 at 8:39 pm #
[...] Web] http://www.protycoon.com Saludos A. Daniel [...]