PHP Script to Detect Googlebot

Nimble75

Regular Member
Joined
Jun 7, 2009
Messages
445
Reaction score
196
Hi does anyone have or know where I can get a piece of PHP script code that can detect if the agent loading the page is a GoogleBot or any other major search engine?

Would greatly appreciate the help

Nimble
 
Code:
$user_agent       = $_SERVER['HTTP_USER_AGENT'];
case (eregi('google',$user_agent)){
echo "Hi GoogleBot";
}
 
Code:
$user_agent       = $_SERVER['HTTP_USER_AGENT'];
case (eregi('google',$user_agent)){
echo "Hi GoogleBot";
}

Oops..sorry I should have mentioned in my first post that I needed it to filter by IP address range, rather than just using the User Agent.

I read that Google can crawl using User Agent values like "Mozilla" and "Safari" (without loading images or executing Javascript etc..) to fake that it is a browser, in order to detect cloaking.
 
Oops..sorry I should have mentioned in my first post that I needed it to filter by IP address range, rather than just using the User Agent.

I read that Google can crawl using User Agent values like "Mozilla" and "Safari" (without loading images or executing Javascript etc..) to fake that it is a browser, in order to detect cloaking.
This is almost impossible considering the fact that they probably have thousands of IP addresses and changing daily. Why do you want to block it anyway? So it doesn't get indexed?
 
I just want to display a backlink if its a bot indexing the site.

This is almost impossible considering the fact that they probably have thousands of IP addresses and changing daily. Why do you want to block it anyway? So it doesn't get indexed?
 
I just want to display a backlink if its a bot indexing the site.
if you know the IP range that you want to display the backlink to then add a redirect into your htaccess file that redirects IP range 127.0.0 or whatever the range is to a second URL with the backlink. Alternatively use PHP on your landing page:

Code:
$ip = $_SERVER['REMOTE_ADDR'];
$ip = str_replace(".","",$ip);

$ip_from = "192.168.0.0";
$ip_to = "192.168.255.255";

$ip_from = str_replace(".","",$ip_from);
$ip_to = str_replace(".","",$ip_to);

if ($ip < $ip_from || $ip > $ip_to) { echo "<a href=\"http://link.com\">Anchor</a>"; }
 
Maybe in your index.php you could add some ajax code to send a POST to itself (index.php) to set a var to True (like javascript = True). If the page is loaded and at the metarefresh the variable is false, then javascript isn't used, so it's maybe a bot or your AM ;)

To refresh after 5 seconds....I know it's a totally lame tech, and there is many other techniques ;)

HTML:
<html>
<body>
<META HTTP-EQUIV="REFRESH" CONTENT=5>
</body>
</html>
 
I just want to display a backlink if its a bot indexing the site.

What's the point? Why is it bad to show the link to non-bots? If Google catches you cloaking, it probably won't be good for you.
 
User Agent Cloaking doesn't work. Too easy to spoof.
 
Yes it is possible to detect by IP address which a lot of people do for creating "door way" pages.
There's a guy called Fantasm? I can't remember if that's his name but he sells weekly updated database of search engine IPs for about $600 a year (could be more)
 
Why not use in_array($_SERVER['REMOTE_ADDR'], $googleips)?

Because you dont have reliable $googleips
You dont build good cloak using ip or agent. You should use some hybrid between server side and user side languages.
 
The most reliable way to detect any search engine is to use detection by RDNS. None can spoof the RDNS of a crawler. This method is 100% accurate. The only minus thing is that you need query every visitor reverse dns. Performance impact is minor compared to use.

I did that code long time ago but because I never receive any help back whenever I need, I will not post it.

However the above hint should give you enough guidelines how to code it on your own.
 
This is almost impossible considering the fact that they probably have thousands of IP addresses and changing daily. Why do you want to block it anyway? So it doesn't get indexed?

By far the best IP list to use is Fantomaster's: http://fantomaster.com/fasvsspy01.html

These guys have been at it for years and their detection system and database are second to none. If you want to do IP-delivery then this is the only solution you need to worry about. No affiliation, but I have been a happy customer of these guys for 6+ years now.

rDNS isn't a fool proof solution because not all bot hits come from the owner that you would expect in the ARIN listings. In fact, there's no such thing as a fool proof solution. It's always risk vs reward when cloaking.
 
it's good dangerous steps and very carefully doing this work
Regard : Mamoon
MY Site :onlinelearnholyquran
 
How came I was not surprised when someone is trying to make money on this? :)

Top 3 search engines are included in my function, who need other crappy search engines? For chinise users, very easy to add baidu spider etc.

Anyone who will take my function in use, i doubt they will pay for fasys when they can enjoy very good free solution ;)

Any other search engine expect those top 3 is quite useless. I barely see traffic from the other search engine expect from google.

I think that page is big bullshit in fact. What are those "800" bots? Shoudl i also code my 800 bots and start taking money from stupid users and provide similar service? No thanks.
 
Last edited:
How came I was not surprised when someone is trying to make money on this? :)

Top 3 search engines are included in my function, who need other crappy search engines?

Anyone who will take my function in use, i doubt they will pay for fasys when they can enjoy very good free solution ;)

Like I said, I have absolutely no affiliation with Fantomaster and team apart from being a long standing customer. I wish I could work with them, but they are waaaay above my level in SEO terms.

You are actually doing BHW readers a real disservice by suggesting that they use rDNS. Not only is it slow as shit, but GOOGLEBOT DOESN'T ALWAYS RESOLVE TO ANY OTHER DOMAIN ASSOCIATED WITH GOOGLE IN THE ARIN LISTINGS. You will not catch every instance of Googlebot using rDNS alone.

It has been well known for a while amongst the cloaking community that Google uses bots running out of satellite companies to bust cloakers.

If you want to be successful with cloaking, you have to be willing to invest the relatively small amount of money it takes to run with the best solution.
 
Back
Top