gravityboy Posted June 4, 2009 Share Posted June 4, 2009 Hi, Can I detect if googlebot is searching my pages and print certain content just for that? Link to comment https://forums.phpfreaks.com/topic/160942-check-for-googlebot-with-php/ Share on other sites More sharing options...
2levelsabove Posted June 4, 2009 Share Posted June 4, 2009 A simple Google search resulted in the following. I take no credit for the code. 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; } Link to comment https://forums.phpfreaks.com/topic/160942-check-for-googlebot-with-php/#findComment-849360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.