Page 1 of 1

Question about Google [bot]

Posted: Sun Dec 26, 2010 3:03 pm
by kingofnumbers
How do I know if Google [bot] visited a PHP page??

Re: Question about Google [bot]

Posted: Mon Dec 27, 2010 3:01 am
by cpetercarter
Muddy footprints on the carpet?

No, seriously, I think that the best method is to use the user-agent strings of visitors. I think that google bots all have a user agent string which contains "Googlebot" or "googlebot", so something like this, included in the code for the page you want to monitor, should do what you want:

Code: Select all

$visitor = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($visitor, 'googlebot'))
{
     // do something eg write to a log file
}
 

Re: Question about Google [bot]

Posted: Mon Dec 27, 2010 9:52 am
by kingofnumbers
Thanks!

Re: Question about Google [bot]

Posted: Mon Dec 27, 2010 10:02 am
by Bind
or you can just look at your server logs and do a 'find' search for 'googlebot' if you do not want to create another set of logs.