/*
- Add to Floodcheck
- Used when entering user input into the database to tell the Floodcheck how many
seconds passed since the user posted something to prevent spamming and flooding.
$ip - The IP to add to the floodcheck, default is the user's IP
*/
public function addFloodCheck($ip = null) {
$file = fopen("Floodcheck.txt", "r");
if ($ip == null)
$ip = $_SERVER['REMOTE_ADDR'];
$floodFile = '';
$found = false;
// sort each line addresses
while (($line = fgets($file)) !== false) {
$line = trim($line);
$flood = explode(",", $line);
// check if ip matches ours
if ($flood[0] == $ip) {
$found = true;
$floodFile .= $ip . ',' . time() . '' . PHP_EOL;
} else
$floodFile .= $flood[0] . ',' . $flood[1] . '' . PHP_EOL;
}
if (!$found)
$floodFile .= $ip . ',' . time() . '';
fclose($file);
// update flood check file
$file = fopen("Floodcheck.txt", "w+");
fwrite($file, $floodFile);
fclose($file);
}
Comments