Sniffing Googlebot using php

Ever wanted to know when Googlebot (google’s search engine spider) visits your site? . Googlebot can be sniffed (detected) easily using php. It is identifiable by the “Googlebot” string in the HTTP_USER_AGENT field it sends with the headers. Here is a simple function called is_google() which returns TRUE if the visitor is Googlebot, else FALSE.

//The function
function is_google() {
if (strpos($_SERVER['HTTP_USER_AGENT'],"Googlebot")) 
 return true
else
 return false
}

Usage

To use the function, just call it using an if statement, here is how :

if (is_google()) 
{
 //do something here if the visitor is Googlebot
//like log the date and time to a file/database
}

Some common uses of this function can be :

  • Analyzing the visit of Googlebot to your sites
  • Spamdexing,Cloaking ( deceiving )
    serving different content (like bulk of links,high ranking keywords etc…) to Googlebot for better rankings
NOTE
Using this function for cloaking and spamdexing is a black hat SEO technique and can cause your site to be blacklisted by Google

Admin

I am a student of Computer Engineering and a freelance web designer and developer with a passion for interface design. WordPress is my framework of choice and I also build web and mobile applications. My Google+ Profile

One response to this entry

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 All rights reserved | Powered by WordPress
Back to top ↑
Theme by dynamicguru.com