Tuesday, January 16, 2007

How to recognize google visit

do you want to know if this visit is a google visit??
here is a simple asp code to do that:
< % robot=request.ServerVariables("HTTP_USER_AGENT") if (Instr(robot,"Googlebot")<>0) then
...
end if
% >

and this is how to do it with php script

< ? define("SYSTEM_FROM_NAME","Your name"); define("SYSTEM_FROM_EMAIL","Your email"); //---this script will send email to webmaster when google visit your pages. if(isset($_SERVER['HTTP_USER_AGENT']) && eregi("googlebot",$_SERVER['HTTP_USER_AGENT'])) { if ($QUERY_STRING != "") { $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?'.$QUERY_STRING; } else { $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; } $today = date("F j, Y, g:i a"); $headers = "From: ".SYSTEM_FROM_NAME." <".SYSTEM_FROM_EMAIL.">";
$message="";
$message.="Googlebot is crawling your site:\n";
$message.="Page: $url\n";
$message.="Date: $today \n";
$message.="IP: ".$_SERVER['REMOTE_ADDR']." \n";
mail(SYSTEM_FROM_EMAIL, "googlebot crawle - $url", "$message",$headers);}
? >

No comments: