are.ehibou.com

November 26, 2007

Php Script To Detect And Verify Googlebot

Filed under: php — admin @ 10:37 pm

Php Script To Detect And Verify Googlebot

function IsGooglebot(){
// check if user agent contains googlebt
if(eregi("Googlebot",$_SERVER['HTTP_USER_AGENT'])){
$ip = $_SERVER['REMOTE_ADDR'];
//server name e.g. crawl-66-249-66-1.googlebot.com

$name = gethostbyaddr($ip);
//check if name ciontains googlebot
if(eregi("Googlebot",$name)){
//list of IP's

$hosts = gethostbynamel($name);
foreach($hosts as $host){
if ($host == $ip){
return true;
}
}
return false; // Pretender, take some action if needed
}else{
return false; // Pretender, take some action if needed
}
}else{
// Not googlebot, take some action if needed
}
return false;
}
  • Share/Bookmark

2 Comments »

  1. hey ,

    nice code i’ll try use it . thank u again .

    peace

    Comment by jackline — January 21, 2009 @ 2:39 pm

  2. Found this through Google, Thanks a lot.

    Comment by gptc — January 17, 2010 @ 12:24 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress