/* * Anti-CC attack depressed to die, not die version. * * If the site refreshes more than 2 times per second, the delay is 5 seconds after the visit. */
$CC _min_nums = ' 1 '; Times, refresh times $CC _url_time = ' 5 '; seconds, delay time $CC _log = ' cc_log.txt '; Enable this behavior logging $CC _forward = ' http://localhost '; Release to URL //-------------------------------------------- Return URL $CC _uri = $_server[' Request_uri ']?$_server[' Request_uri ']:($_server[' php_self ']?$_server[' php_self ']:$_SERVER[' Script_name ']); $site _url = ' http://'. $_server [' Http_host ']. $CC _uri; Enable session if (!isset ($_session)) session_start (); $_session["Visiter"] = true; if ($_session["Visiter"] <> true) { echo ""; Header ("Location:". $CC _forward); Exit } $timestamp = time (); $CC _nowtime = $timestamp; if (session_is_registered (' Cc_lasttime ')) { $CC _lasttime = $_session[' cc_lasttime '); $CC _times = $_session[' cc_times ') + 1; $_session[' cc_times '] = $CC _times; }else{ $CC _lasttime = $CC _nowtime; $CC _times = 1; $_session[' cc_times '] = $CC _times; $_session[' cc_lasttime '] = $CC _lasttime; } Get real IP if (Isset ($_server)) { $real _ip = $_server[' http_x_forwarded_for '); }else{ $real _ip = getenv ("Http_x_forwarded_for"); } Print_r ($_session); //Release IP if (($cc _nowtime-$cc _lasttime) <=0) { if ($cc _times>= $cc _min_nums) { if (!empty ($CC _log)) cc _log (Get_ip (), $real _ip, $cc _log, $cc _uri); Generate Log echo "Wait Please, try again later!"; //printf (' Your refresh is too fast, please later. '); //header ("Location:". $CC _forward); Exit; } }else{ $cc _times = 0; $_session[' cc_lasttime '] = $cc _nowtime; $_session[' cc_times '] = $cc _times;< br>} //Record cc log function Cc_log ($client _ip, $real _ip, $cc _log, $cc _uri) { $temp _time = Date ("Y-m-d h:i:s", Time () + 360 0*8); $temp _result = "[". $temp _time. "] [Client ". $client _ip."] "; if ($real _ip) $temp _result. = "[real". $real _ip. "]"; $temp _result. = $cc _uri. "RN"; $handle = fopen ("$cc _log", "RB"), $oldcontent = Fread ($handle, FileSize ("$CC _log")), Fclose ($handle); br> $newcontent = $temp _result. $oldcontent; $fhandle =fopen ("$cc _log", "WB"), Fwrite ($fhandle, $newcontent , strlen ($newcontent)); Fclose ($fhandle); } Get online IP function Get_ip () { Global $_c;
if (Empty ($_c[' client_ip ')) { if (getenv (' http_client_ip ') && strcasecmp (getenv (' http_client_ip '), ' unknown ') { $client _ip = getenv (' http_client_ip '); } elseif (getenv (' http_x_forwarded_for ') && strcasecmp (getenv (' http_x_forwarded_for '), ' unknown ') { $client _ip = getenv (' http_x_forwarded_for '); } elseif (getenv (' remote_addr ') && strcasecmp (getenv (' remote_addr '), ' unknown ') { $client _ip = getenv (' remote_addr '); } elseif (Isset ($_server[' remote_addr ") && $_server[' remote_addr '] && strcasecmp ($_server[' Remote_ ADDR '], ' unknown ') { $client _ip = $_server[' remote_addr '); } $_c[' client_ip ' = $client _ip? $client _ip: ' Unknown '; } Return $_c[' client_ip ']; } ?> |