Archives for tag —googlebot user agent detecting using php

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
© 2010 Dynamic Guru All rights reserved — About UsContactMujtaba