/* * CC attack prevention is depressing. * * If the number of refresh times of the website exceeds 2 times per second, the website will be accessed after 5 seconds. */ $ Cc_min_nums = '1'; // times, refresh count $ Cc_url_time = '5'; // second, delay time // $ Cc_log = 'cc_log.txt '; // enable this behavior log $ 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 "script setTimeout (" window. location. href = '$ cc_forward'; ", 1); script"; // 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; } // Obtain the real IP address If (isset ($ _ SERVER )){ $ Real_ip = $ _ SERVER ['http _ X_FORWARDED_FOR ']; } Else { $ Real_ip = getenv ("HTTP_X_FORWARDED_FOR "); } // Print_r ($ _ SESSION ); // Release the IP address 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 a log Echo "Wait please, try again later! Script setTimeout ("window. location. href = '$ site_url';", 5000); script "; // Printf ('You refresh too fast, please wait. '); // Header ("Location:". $ cc_forward ); Exit; } } Else { $ Cc_times = 0; $ _ SESSION ['CC _ lasttime'] = $ cc_nowtime; $ _ SESSION ['cc_times '] = $ cc_times; } // Record cc logs Function cc_log ($ client_ip, $ real_ip, $ cc_log, $ cc_uri ){ $ Temp_time = date ("Y-m-d H: I: s", time () + 3600*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 ); $ Newcontent = $ temp_result. $ oldcontent; $ Fhandle = fopen ("$ cc_log", "wb "); Fwrite ($ fhandle, $ newcontent, strlen ($ newcontent )); Fclose ($ fhandle ); } // Obtain the online IP address 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']; } ?> |