Skip to content

Tuesday, November 10th, 2009

Poorman’s Cloaking Script

June 13, 2006 by Gilad  
Filed under Computers

I know that this is more of a programming aspect, but it can be useful for SEO as well.

While registering some expired domains today, I needed a quick method to:

1. Track the visitors.
2. Recognize whether or not it is a search engine.
3. Redirect search engines to a different site.

This is what I came up with to get the job done:
< ?php
include_once ('tracker.php');
$serverUA = $_SERVER['HTTP_USER_AGENT'];
$UA1 = "Googlebot";
$UA2 = "Mediapartners";
if (strstr($serverUA, $UA1)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.where-to-redirect.com/');
exit;
} elseif (strstr($serverUA, $UA2)) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.where-to-redirect.com/');
exit;
} else {
echo 'Text for real visitors';
};
?>

To make this work, just insert the appropriate useragents you’d like to redirect for the $UA1 and $UA2 variables (in this case it is Google and Adsense bots), and edit the text you’d like to present to real (non search engine) visitors.

PS. The first include_once line includes a tracking script that writes all visitor’s information. This is good for monitoring purposes (ex. to know if bots have visited your sites)

  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google
  • TwitThis
  • Reddit
  • Yahoo! Buzz
  • Slashdot
  • E-mail this story to a friend!
  • BallHype
  • YardBarker

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


About Us | Advertise with us | Blog for EveryJoe | Privacy Policy | Terms of Use
Get This Theme | Sitemap


All content is Copyright © 2005-2009 b5media. All rights reserved.