Advertisement
reenadak

flood check

Feb 20th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1.  
  2.     /*
  3.     - Add to Floodcheck
  4.     - Used when entering user input into the database to tell the Floodcheck how many
  5.       seconds passed since the user posted something to prevent spamming and flooding.
  6.    
  7.     $ip     - The IP to add to the floodcheck, default is the user's IP
  8.     */
  9.    
  10.     public function addFloodCheck($ip = null) {
  11.         $file = fopen("Floodcheck.txt", "r");
  12.        
  13.         if ($ip == null)
  14.             $ip = $_SERVER['REMOTE_ADDR'];
  15.        
  16.         $floodFile = '';
  17.         $found = false;
  18.        
  19.         // sort each line addresses
  20.         while (($line = fgets($file)) !== false) {
  21.             $line = trim($line);
  22.             $flood = explode(",", $line);
  23.            
  24.             // check if ip matches ours
  25.             if ($flood[0] == $ip) {
  26.                 $found = true;
  27.                 $floodFile .= $ip . ',' . time() . '' . PHP_EOL;
  28.             } else
  29.                 $floodFile .= $flood[0] . ',' . $flood[1] . '' . PHP_EOL;
  30.         }
  31.        
  32.         if (!$found)
  33.             $floodFile .= $ip . ',' . time() . '';
  34.        
  35.         fclose($file);
  36.        
  37.         // update flood check file
  38.         $file = fopen("Floodcheck.txt", "w+");
  39.         fwrite($file, $floodFile);
  40.         fclose($file);
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement