Cloaking: All You Ever Wanted to Know (But Were too Afraid of Google to Ask)
Posted by Teifion - 08/12/08 at 01:12:28 pmWhat is cloaking and should I do it?
Cloaking is where you display a different page depending on who is viewing it, for example showing different content to Google so as to alter your SEO ranking, this is risky as explained by Jeff Bentley. There are quite a few ways to do this, this post is aimed at those that have some programming knowledge, the examples will use PHP and Javascript.
IP matching
The first method is to get the IP address of the user, if they come from Google HQ then you display different content to them. The code itself is quite simple.
$blockedIP = array( '100.120.150.240', '100.110.150.240', '100.130.150.240', '100.160.150.199' ); if (in_array($_SERVER['REMOTE_ADDR'], $blockedIP)) { echo 'Content you want Google to see'; } else { echo 'Content you want everybody else to see'; }
Sadly you can’t use an asterisk wildcard with this method, this makes blocking an entire range of IP’s very hard. Thankfully there is a (more complicated) way to block ranges using regular expressions.
$blockedIPGrep = array( '/62.56.110.2[0-9][0-9]?/',//Matches 62.56.110.20 - 62.56.110.255 ); $showSEO = false; foreach ($blockedIPGrep as $match) { preg_match($match, $_SERVER['REMOTE_ADDR'], $matches); var_dump($matches); $showSEO = true; } if ($showSEO) { echo 'Content you want Google to see'; } else { echo 'Content you want everybody else to see'; }
If you don’t know regular expressions then I’d avoid the second example but if you do then it can save you a lot of space.
User agent
This is a very ineffective method because it’s so very easy to lie about this. Infact, some browsers have it built right in. However, I’m including it so you can see how it’s done.
$blockedAgents = array( 'Google monkey spider thingie', 'Yahoo spider monkey thingie', ); if (in_array($_SERVER['HTTP_USER_AGENT'], $blockedAgents)) { echo 'Content you want Google to see'; } else { echo 'Content you want everybody else to see'; }
Javascript
Google does many things, it can even run Javascript. Combined with the fact that if you somehow managed to make it so that Google didn’t run JS on your site, you’d fail a hand test very easily. Thus I will not go into javascript.
Our Thoughts…
If you’re Google, or if you’re working on a client site - cloaking is bad and wrong, and you shouldn’t do it. Unless the client wants you to.
If you’re not - it works. Play with it, hang around with the right (read: wrong) croud, learn all you can and enjoy! Just don’t do it where it matters if you get banned.
1 Trackbacks/Pingbacks
- Pingback: Internet Marketing Toronto - Ignite! » Blog Archive » The Pitfalls Of Cloaking on December 12, 2008





Leave a comment
You must be logged in to post a comment.