Random PHP Code: Referer Cloaking
Here's an idea. Instead of cloaking to search engines, let's cloak to your search engine visitors. Here's how...
1. Place the following code on the page you wish to cloak (or simply drop it in a global include so you can cloak pages at will ;):
<?php
$agent = strtolower($HTTP_REFERER);
if(strpos($agent, "google") != ""){
$search = "1";
}
if(strpos($agent, "altavista") != ""){
$search = "1";
}
if(strpos($agent, "lycos") != ""){
$search = "1";
}
if(strpos($agent, "ask") != ""){
$search = "1";
}
if(strpos($agent, "yahoo") != ""){
$search = "1";
}
?>
Before I go on, the code above is pretty much the same as the code from Esrun's Cloaked Content Generator script with one minor change...
The original script from Esrun contained:
$agent = "Rabbit Fire Storm".strtolower($HTTP_USER_AGENT);
which I simply switched out with:
$agent = strtolower($HTTP_REFERER);
As you can see all I did was change it to check for the Referer instead of the user-agent (I didn't change the variable name, $agent as I wanted to keep this simple to demonstrate). The "Rabbit Fire Storm" part is something I would love to hear more about from Esrun some day but as far as what it's doing, removing it won't change the desired functionality. To be clear, what this is doing is using the built-in PHP funtion, strtolower which, as you'd expect, converts the string (in this case what's returned from another built in feature of PHP called a Superglobal) into lowercase characters. In other words, that one line grabs the Referer, converts it to lowercase, and assigns it to the $agent variable so you can work with it later. Since we're simply checking for the name of the search engine in the next step, removing the Rabbit Fire Storm part won't change anything.
2. Now let's do some magic :). Let's say you want to do something naughty like cloak inline styling (or perhaps an image) to your search engine visitors so they won't see anything they're not supposed to. Simply place the following code within the HTML tag (i.e. div, span, etc) in which you wish to use the cloaked styling:
<?php if($search !== "1") { echo ' style="display:none;"'; }?>>
Now for the explanation. So let's say you go to Google and do a search for something that returns the page you placed this code on in the search results. When you click on the result, your Referer will contain the string, "google" in it thus the value, "1" will be assigned to the $search variable. The if statement directly above simply checks whether the $search variable is not equal (!==) to "1" and, if it isn't, displays (echo) the styling.
Million Dollar Question to Google
And here's where it gets REALLY interesting. What if I took the script and slimmed it down to only cloak to Google but then added a bit of code to check for the User-Agent as well:
<?php
$referer = strtolower($HTTP_REFERER);
$agent = strtolower($HTTP_USER_AGENT);
if(strpos($referer, "google") != ""){
$search = "1";
}
if (strpos($agent, "google") != "") {
$search = "1";
}
?>
Google visitors would then see exactly the same thing as Google does. I wonder if Maile considers this a "high-risk" technique as well. :)
Script for Cloaking based on Both the Referer and the User-Agent
Since it was easy to add the extra if statements, here's a modified version of the script above that performs BOTH referer and user-agent checking. In other words, the following script checks if the referer OR the user-agent contains the relative strings (i.e. "teoma" for user-agent and "ask" for referer) for all of the major search engines and if it does, sets the $search variable to "1" so you can work with it later (as demonstrated earlier with <?php if($search !== "1") { echo ' style="display:none;"'; }?>>).
<?php
$referer = strtolower($_SERVER['HTTP_REFERER']);
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($referer, "google") != ""){
$search = "1";
}
if(strpos($agent, "google") != ""){
$search = "1";
}
if(strpos($referer, "altavista") != ""){
$search = "1";
}
if(strpos($agent, "altavista") != ""){
$search = "1";
}
if(strpos($referer, "yahoo") != ""){
$search = "1";
}
if(strpos($agent, "yahoo") != ""){
$search = "1";
}
if(strpos($agent, "slurp") != ""){
$search = "1";
}
if(strpos($referer, "lycos") != ""){
$search = "1";
}
if(strpos($agent, "lycos") != ""){
$search = "1";
}
if(strpos($referer, "ask") != ""){
$search = "1";
}
if(strpos($agent, "teoma") != ""){
$search = "1";
}
if(strpos($agent, "ArchitectSpider") != ""){
$search = "1";
}
?>
Hope it helps and thanks Esrun for giving me something to do today.






