View file templates/antiflood.php

File size: 763B
<?php 
function CheckIP () 
{global $floodstime;
	
$flag= false;	
$fs= filesize(BASEDIR.'data/antiflood.dat');
$f= fopen(BASEDIR.'data/antiflood.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(BASEDIR.'data/antiflood.dat', 'a+');	
flock($f, LOCK_EX);
ftruncate($f, 0);
@fwrite($f, serialize($arr));
fflush($f);
flock($f, LOCK_UN);
fclose($f);
return $flag;
}
?>