b5media.com

Advertise with us

Enjoying this blog? Check out the rest of the Technology Channel Subscribe to this Feed

Search Engine Herald

Poorman’s Cloaking Script

by Gilad on June 13th, 2006

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)

POSTED IN: Search Engine Optimization

0 opinions for Poorman’s Cloaking Script

  • No one has left a comment yet. You know what this means, right? You could be first!

Have an opinion? Leave a comment: