reenadak icon

flood checker

reenadak | PRO | 02/20/18 06:56:35 PM UTC | 0 ⭐ | 321 👁️ | Never ⏰ | []
PHP |

840 B

|

None

|

0 👍

/

0 👎

    /*
    - Flood Checker
    - Checks that the user is not spamming or "flooding" the database.
    
    $interval     - How many seconds between each post from this IP address
    $ip           - The IP to flood check, default is the user's IP
    */
    
    public function floodCheck($interval = 15, $ip = null) {
        $success = true;
        
        if (file_exists("Floodcheck.txt")) {
            $file = fopen("Floodcheck.txt", "r");
 
            if ($ip == null)
                $ip = $_SERVER['REMOTE_ADDR'];
            
            // sort each line addresses
            while (($line = fgets($file)) !== false) {
                $line = trim($line);
                $flood = explode(",", $line);   
 
                // check if ip matches ours
                if ($flood[0] == $ip) {
                    // check if the flood check is successful
                    if ((time() - $flood[1]) < $interval)
                        $success = false;
                }
            }
            
            fclose($file);
        }
        
        return $success;
    }

Comments