Question about Google [bot]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingofnumbers
Forum Newbie
Posts: 6
Joined: Thu Dec 23, 2010 9:35 pm

Question about Google [bot]

Post by kingofnumbers »

How do I know if Google [bot] visited a PHP page??
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Question about Google [bot]

Post 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
}
 
kingofnumbers
Forum Newbie
Posts: 6
Joined: Thu Dec 23, 2010 9:35 pm

Re: Question about Google [bot]

Post by kingofnumbers »

Thanks!
Bind
Forum Contributor
Posts: 102
Joined: Wed Feb 03, 2010 1:22 am

Re: Question about Google [bot]

Post 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.
Post Reply