Salut,
voici 2 scripts de cloaking que j'ai récupéré sur le net.
Voici le 1er
/* if yes, we catch its query (param. q in the URL) */
if ( $isGoogleReferer && preg_match ('!q=([^\&#]*)!i',$_SERVER["HTTP_REFERER"],
$matches) )
{ $googleQuery = $matches[1]; }
else { $googleQuery = null; }
/* if the query were captured, we make it usable */
if ( $googleQuery )
{ $googleQuerySanitize = preg_replace('![^a-z0-9éèàùçÇÉÀÈÙêÊ\s]!i',
' ', rawurldecode($googleQuery) );
$google = str_replace("+", " ", $googleQuerySanitize); }
else { $googleQuery = ''; }
// END STEP 1 (detection of Google if it's the referer)
// credit for this part : most of the code is a
// simplier rewriting of a snipet by Romain Follet :
// http://www.cooldev.net/article-93-ya-pas-que-google-dans-la-vie.html
// thanks to him for this piece of code :D
/* STEP 1 BIS : détection of Google by the IP or DNS host */
$ip = strval($_SERVER['REMOTE_ADDR']); // conversion to string
$host = gethostbyaddr($ip);
$GoogleByHost = false;
$GoogleByIP = false ; // default values
if (preg_match("/crawl-66-249-[\d]{1,3}-[\d]{1,3}\.googlebot\.com/", $host))
{$GoogleByDNS = true;}
if (preg_match("/66\.249\.[\d]{1,3}\.[\d]{1,3}/", $ip))
{$GoogleByIP = true;}
// END STEP 1 BIS
// credits : http://www.actulab.com/identification-des-robots.php
// and : http://www.robots.darkseoteam.com/
// ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/* STEP 2 : definig the redirection URLs*/
/* URL for Googlebot-Image */
$URLsForGooglebotImage = array(
"http://www.someurl.net",
"http://www.someurl.net",
"http://www.someurl.net"
);
/* URL for Googlebot */
$URLsForGooglebot = array(
"http://www.someurl.net",
"http://www.someurl.net",
"http://www.someurl.net"
);
/* building the same query in others search engines */
$sameQueryButInYauba = "http://www.yauba.com/?q={$googleQuery}&target=all";
$sameQueryButInYahoo ="http://search.yahoo.com/search?p={$googleQuery}";
$sameQueryButInIxquick = "http://ixquick.com/do/metasearch.pl?query=
{$googleQuery}&cat=web&pl=ff&language=english";
/* URLS to which people coming not from Google will be redirected */
$UrlsForThoseComingFromGoogle = array(
"$sameQueryButInYauba",
"$sameQueryButInYauba",
"$sameQueryButInYauba",
"$sameQueryButInYauba",
"$sameQueryButInYauba",
"$sameQueryButInYahoo",
"$sameQueryButInYahoo",
"$sameQueryButInYahoo",
"$sameQueryButInIxquick",
"$sameQueryButInIxquick"
); // Yauba 50%, Yahoo 30%, Ixquick 20%
/* URL pfor the other visitors */
$UrlsForThoseComingNotFromGoogle = array(
"http://www.someurl.net",
"http://www.someurl.net",
"http://www.someurl.net"
);
// END STEP 2 (defining redirection URLs)
// ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/* STEP 3 : detection of the user-agent */
/* looking for "Googlebot-Image" or "Googlebot" in the signature of the UA */
$IsGooglebotImage = strpos($_SERVER["HTTP_USER_AGENT"],"Googlebot-Image");
$IsGooglebot = strpos($_SERVER["HTTP_USER_AGENT"],"Googlebot");
// END STEP 3
// ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
/* STEP 4 : redirection */
/* if UA is Googlebot ou Googlebot-Image */
if ($GoogleByDNS || $GoogleByIP || $IsGooglebot !== false)
{
if ($GoogleByIP || $GoogleByDNS)
{
/* choosing an url randomly */
$indice = array_rand($URLsForGooglebot);
$destinationFinale = $URLsForGooglebot[$indice];
}
/* is the UA is Googlebot-Image */
elseif ($IsGooglebotImage !== false)
{
$indice = array_rand($URLsForGooglebotImage);
$destinationFinale = $URLsForGooglebotImage[$indice];
}
/* if UA is Googlebot (normal) */
else
{
/* chosing randomly one URL */
$indice = array_rand($URLsForGooglebot);
$finalDestination = $URLsForGooglebot[$indice];
}
/* final operation in case of Google visiting the page */
header("Location: ".$finalDestination."",TRUE,302);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="mis">
<head>
<title>Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="refresh" content="0;URL='.$finalDestination.'">
</head>
<body>
<p><a href="'.$finalDestination.'" rel="me">my website</a>.</p>
</body>
</html>
';
} // END id UA is Googlebot or Googlebot-Image
/* if UA is no Googlebot */
else
{
/* if visitor comes form Google */
if ($isGoogleReferer && $googleQuery)
{
$indice = array_rand($UrlsForThoseComingFromGoogle);
$finalDestination = $UrlsForThoseComingFromGoogle[$indice];
}
/* if not from Google */
else
{
$indice = array_rand($UrlsForThoseComingNotFromGoogle);
$finalDestination = $UrlsForThoseComingNotFromGoogle[$indice];
}
/* finale operation : redirecting */
header("Location: ".$finalDestination."",TRUE,302);
}
// END STEP 4 (redirection)
// ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
exit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>First name NAME</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p><a href="http://wwww.mywebsite.net" rel="me">my web site</a>.</p>
</body>
</html>
et voici le 2e avec une classe PHP
/*
// +----------------------------------------------------------------------+
// | SimpleCloak |
// | Class for cloaking content |
// | http://www.SEOEgghead.com |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 Jaimie Sirovich and Cristian Darie |
// +----------------------------------------------------------------------+
*/
// load configuration file
require_once('config.inc.php');
class SimpleCloak
{
// returns the confidence level
function isSpider($spider_name = '', $check_uas = true, $check_ips = true)
{
// default confidence level to 0
$confidence = 0;
// matching user agent?
if ($check_uas)
if (SimpleCloak::_get(0, $spider_name, 'UA', $_SERVER['HTTP_USER_AGENT']))
$confidence += 2;
// matching IP?
if ($check_ips)
if (SimpleCloak::_get(0, $spider_name, 'IP', '', $_SERVER['REMOTE_ADDR']))
$confidence += 3;
// return confidence level
return $confidence;
}
// retrieve cloaking data filtered by the supplied parameters
function _get($id = 0, $spider_name = '', $record_type = '',
$value = '', $wildcard_value = '')
{
// by default, retrieve all records
$q = " SELECT cloak_data.* FROM cloak_data WHERE TRUE ";
// add filters
if ($id) {
$id = (int) $id;
$q .= " AND id = $id ";
}
if ($spider_name) {
$spider_name = mysql_escape_string($spider_name);
$q .= " AND spider_name = '$spider_name' ";
}
if ($record_type) {
$record_type = mysql_escape_string($record_type);
$q .= " AND record_type = '$record_type' ";
}
if ($value) {
$value = mysql_escape_string($value);
$q .= " AND value = '$value' ";
}
if ($wildcard_value) {
$wildcard_value = mysql_escape_string($wildcard_value);
$q .= " AND ( '$wildcard_value' = value OR '$wildcard_value' LIKE CONCAT(value, '.%') ) ";
}
// Connect to MySQL server
$dbLink = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die("Could not connect: " . mysql_error());
// Connect to the seophp database
mysql_select_db(DB_DATABASE) or die("Could not select database");
// execute the query
$tmp = mysql_query($q);
// close database connection
mysql_close($dbLink);
// return the results as an associative array
$rows = array();
while ($_x = mysql_fetch_assoc($tmp)) {
$rows[] = $_x;
}
return $rows;
}
// updates the entire database with fresh spider data, but only if our data is
// more than 7 days old, and if the online version from iplists.org has changed
function updateAll()
{
// Connect to MySQL server
$dbLink = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die("Could not connect: " . mysql_error());
// Connect to the seophp database
mysql_select_db(DB_DATABASE) or die("Could not select database");
// retrieve last update information from database
$q = "SELECT cloak_update.* FROM cloak_update";
$tmp = mysql_query($q);
$updated = mysql_fetch_assoc($tmp);
$db_version = $updated['version'];
$updated_on = $updated ['updated_on'];
// get the latest update more recent than 7 days, don't attempt an update
if (isset($updated_on) &&
(strtotime($updated_on) > strtotime("-604800 seconds")))
{
// close database connection
mysql_close($dbLink);
// return false to indicate an update wasn't performed
return false;
}
// read the latest iplists version
$version_url = 'http://www.iplists.com/nw/version.php';
$latest_version = mysql_escape_string(file_get_contents($version_url));
// if no updated version information was retrieved, abort
if (!$latest_version)
{
// return false to indicate an update wasn't performed
return false;
}
// save the update data
$q = "DELETE FROM cloak_update";
mysql_query($q);
$q = "INSERT INTO cloak_update (version, updated_on) " .
"VALUES('$latest_version', NOW())";
mysql_query($q);
// if we already have the current data, don't attempt an update
if ($latest_version == $db_version)
{
// close database connection
mysql_close($dbLink);
// return false to indicate an update wasn't performed
return false;
}
// update the database
SimpleCloak::_updateCloakingDB('google',
'http://www.iplists.com/nw/google.txt');
SimpleCloak::_updateCloakingDB('yahoo',
'http://www.iplists.com/nw/inktomi.txt');
SimpleCloak::_updateCloakingDB('msn',
'http://www.iplists.com/nw/msn.txt');
SimpleCloak::_updateCloakingDB('ask',
'http://www.iplists.com/nw/askjeeves.txt');
SimpleCloak::_updateCloakingDB('altavista',
'http://www.iplists.com/nw/altavista.txt');
SimpleCloak::_updateCloakingDB('lycos',
'http://www.iplists.com/nw/lycos.txt');
SimpleCloak::_updateCloakingDB('wisenut',
'http://www.iplists.com/nw/wisenut.txt');
// close connection
mysql_close($dbLink);
// return true to indicate a successful update
return true;
}
// update the database for the mentioned spider, by reading the provided URL
function _updateCloakingDB($spider_name, $url,
$ua_regex = '/^# UA "(.*)"$/m', $ip_regex = '/^([0-9.]+)$/m')
{
// use cURL to read the data from $url
// NOTE: additional settings are required when accessing the web through a proxy
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
$result = curl_exec($ch);
curl_close($ch);
// use _parseListURL to parse the list of IPs and user agents
$lists = SimpleCloak::_parseListURL($result, $ua_regex, $ip_regex);
// if the user agents and IPs weren't retrieved, we cancel the update
if (!$lists['ua_list'] || !$lists['ip_list']) return;
// lock the cloack_data table to avoid concurrency problems
mysql_query('LOCK TABLES cloak_data WRITE');
// delete all the existing data for $spider_name
SimpleCloak::_deleteSpiderData($spider_name);
// insert the list of user agents for the spider
foreach ($lists['ua_list'] as $ua) {
SimpleCloak::_insertSpiderData($spider_name, 'UA', $ua);
}
// insert the list of IPs for the spider
foreach ($lists['ip_list'] as $ip) {
SimpleCloak::_insertSpiderData($spider_name, 'IP', $ip);
}
// release the table lock
mysql_query('UNLOCK TABLES');
}
// helper function used to parse lists of user agents and IPs
function _parseListURL($data, $ua_regex, $ip_regex)
{
$ua_list_ret = preg_match_all($ua_regex, $data, $ua_list);
$ip_list_ret = preg_match_all($ip_regex, $data, $ip_list);
return array('ua_list' => $ua_list[1], 'ip_list' => $ip_list[1]);
}
// inserts a new row of data to the cloaking table
function _insertSpiderData($spider_name, $record_type, $value)
{
// escape input data
$spider_name = mysql_escape_string($spider_name);
$record_type = mysql_escape_string($record_type);
$value = mysql_escape_string($value);
// build and execute the INSERT query
$q = "INSERT INTO cloak_data (spider_name, record_type, value) " .
"VALUES ('$spider_name', '$record_type', '$value')";
mysql_query($q);
}
// delete the cloaking data for the mentioned spider
function _deleteSpiderData($spider_name)
{
// escape input data
$spider_name = mysql_escape_string($spider_name);
// build and execute the DELETE query
$q = "DELETE FROM cloak_data WHERE spider_name='$spider_name'";
mysql_query($q);
}
}
?>
J'ai pas testé ces scripts, je me contente juste de les partager ici.