Detecter les crawlers des moteurs de recherche
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Is_bot | |
* traque la présence d'un bot par plage d'ip | |
* | |
* @param string $ip | |
* @param array $array_bots | |
* @return string|false | |
*/ | |
function is_bot ($ip,$array_bots) { | |
$ip = strval($ip); | |
$reponse = false; | |
foreach($array_bots as $bot=>$val) { | |
foreach($array_bots[$bot] as $ip_bot) { | |
$reponse = strpos($ip,$ip_bot); | |
if ($reponse !== FALSE) return $bot; | |
} | |
} | |
return $reponse; | |
} | |
// Utilisation | |
$bots = array( | |
'google' => array('216.239.46','64.68.8','66.249.','64.233.173'), | |
'yahoo' => array('66.196.','68.142.','202.165.','66.142.') | |
); | |
$test = is_bot('216.239.46.654',$bots); //renverra TRUE car 216.239.46 est présent dans l'ip. Utilisez $_SERVER['REMOTE_ADDR'] pour automatiser | |
if($test != FALSE) { | |
//action affichage bot ou cloaking ;) | |
$bot = $test; | |
echo "bot présent<br/>"; | |
echo $bot; | |
} else { | |
echo "pas de bot"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment