来源:http://www.sem9.com/thread-20025-1.html
<?php
error_reporting(0);
$url='http://www.baidu.com';
$str=strpos($_SERVER['HTTP_REFERER'],'google');
if($str){
header("location:{$url}");
exit();
}
$iipp=$_SERVER["REMOTE_ADDR"];
//$iipp="8.255.255.256";
$iipp=myip2long($iipp);
$ips=array(134217728,150994943,1062518496,1062518527,1074918400,1074918431,1074921472,1074925567,1078214656,1078222847,1081575648,1081575655,1081896984,1081896991,1081927080,1081927087,1082183584,1082183599,1089052672,1089060863,1103424288,1103424303,1104396896,1104396911,1104572512,1104572543,1104609120,1104609135,1105036720,1105036735,1105135664,1105135679,1113980928,1113985023,1119913504,1119913519,1123631104,1123639295,1132356616,1132356623,1176535040,1176543231,1180172288,1180359472,1180359479,1180359496,1180359503,1180434431,1208926208,1208942591,1249705984,1249771519,1823129600,1823145983,1823539200,1823571967,2159111488,2159111679,2159128096,2159128111,2398748672,2398879743,2899902464,2899967999,2902261760,2902327295,2915172352,2915237887,3232890880,3233021951,3344429056,3344430079,3459234728,3459234735,3468331392,3468331455,3475195328,3475195391,3481178112,3481182207,3487539200,3487543295,3494556048,3494556063,3512041472,3512074239,3518562304,3518627839,3522775360,3522775367,3625975808,3626237951,3627728896,3627737087,3639549952,3639558143); //转意过的谷歌蜘蛛IP,可自行添加
function checkip($url,$ips){
foreach ($ips as $key =>$value) {
if ($url<=$value&&sus($value)&&$url>=$ips[$key-1]) {
return true;
}
}
return false;
}
function myip2long($ip){
$ip_arr = split('\.',$ip);
$iplong = (16777216 * intval($ip_arr[0])) + (65536 * intval($ip_arr[1])) + (256 * intval($ip_arr[2])) + intval($ip_arr[3]);
return $iplong;
}
function sus($n){
return $n%2==1?1:0;
}
if(checkip($iipp,$ips)){
header("location:http://www.baidu.com");
}
?>