View file darkworld/files/flood.php

File size: 747B
<?php 

$floodstime=5;

function CheckIP () 
{global $floodstime;
	
$flag= false;	
$fs= filesize('data/flood.dat');
$f= fopen('data/flood.dat', 'r');
flock($f, LOCK_SH);
$arr= @unserialize(fread($f, $fs));
flock($f, LOCK_UN);
fclose($f);
$IP= $_SERVER['REMOTE_ADDR'];
$IP=htmlspecialchars(stripslashes($IP));
$t= time();			
if (isset($arr)) { 
foreach ($arr as $k=>$v)
if ($v<$t) unset($arr[$k]);
} else $arr= array ();
if (!isset($arr[$IP])) {	
$arr[$IP]= $t + $floodstime;	
$flag= false;
} else {
$arr[$IP]= $t + $floodstime;	
$flag= true;
}
$f= fopen('data/flood.dat', 'a+');	
flock($f, LOCK_EX);
ftruncate($f, 0);
@fwrite($f, serialize($arr));
fflush($f);
flock($f, LOCK_UN);
fclose($f);
return $flag;
}
?>