Ludatha
04-27-2008, 03:05 PM
Hello, I am trying to implent a 'Anti-Flood' protection system on my website.
You can post 5 times in 30 seconds, if you post more it will not allow it and say they need to wait.
It works fine, but after you have posted 5 times, it never allows you to post again, even after 30 seconds...
Here is the function:
function postMessage ($type, $idValue){
// This function handels all the postings, such as comment, form post etc.
// Anti flood, ip logging enabled
// $type = (0 = Content Comment, 1 = Profile Comment, 2 = Forum Comment, 3 = Portal Comment)
// $idValue = What id the comment is for (like member 135 or portal id 742)
$wait_time = 30; // In seconds.
$limit = time() - $wait_time; // this makes a timestamp from exactly five minutes ago.
$check = mysql_query("SELECT COUNT(*) AS result FROM `comment` WHERE `ip` = '".$_SERVER['REMOTE_ADDR']."' AND `timeS` < $limit");
$r = mysql_fetch_array($check, MYSQL_ASSOC);
$number = $r['result'];
$set_amount = 5;
if($number < $set_amount) { // If they're below the limit (i.e. if they're not spammers :P)
$author = $_SESSION['username']; // Get the username
$forType = $type;
$forId = $idValue;
$date = date("F j, Y, g:i a"); // Set the date format
$ip = $_SERVER['REMOTE_ADDR']; // Get the users IP
$content2 = $_POST['content'];
$extra = $_POST['extra'];
if($type == 0){
$forType = 'content';
}
elseif($type == 1){
$forType = 'profile';
}
elseif($type == 2){
$forType = 'forum';
}
elseif($type == 3){
$forType = 'portal';
}
$sql="INSERT INTO comment(author, forType, forId, date, ip, content, extra, timeS)VALUES('$author', '$forType', '$forId', '$date', '$ip', '$content2', '$extra', '".time()."')";
$result=mysql_query($sql);
echo mysql_error();
echo 'Your post was added.';
// As the post was added, add 1 to their comment count
if($_SESSION['username'] !==$_GET['id']){
$sql1="UPDATE members SET hits = hits +1 WHERE username='$member'";
$result1=mysql_query($sql1);
}
}
else
{
echo 'Sorry but you can\'t post more than '.$set_amount.' times in 30 seconds. Try again later.';
}
} // End Function
Any ideas of how to get it working?
You can post 5 times in 30 seconds, if you post more it will not allow it and say they need to wait.
It works fine, but after you have posted 5 times, it never allows you to post again, even after 30 seconds...
Here is the function:
function postMessage ($type, $idValue){
// This function handels all the postings, such as comment, form post etc.
// Anti flood, ip logging enabled
// $type = (0 = Content Comment, 1 = Profile Comment, 2 = Forum Comment, 3 = Portal Comment)
// $idValue = What id the comment is for (like member 135 or portal id 742)
$wait_time = 30; // In seconds.
$limit = time() - $wait_time; // this makes a timestamp from exactly five minutes ago.
$check = mysql_query("SELECT COUNT(*) AS result FROM `comment` WHERE `ip` = '".$_SERVER['REMOTE_ADDR']."' AND `timeS` < $limit");
$r = mysql_fetch_array($check, MYSQL_ASSOC);
$number = $r['result'];
$set_amount = 5;
if($number < $set_amount) { // If they're below the limit (i.e. if they're not spammers :P)
$author = $_SESSION['username']; // Get the username
$forType = $type;
$forId = $idValue;
$date = date("F j, Y, g:i a"); // Set the date format
$ip = $_SERVER['REMOTE_ADDR']; // Get the users IP
$content2 = $_POST['content'];
$extra = $_POST['extra'];
if($type == 0){
$forType = 'content';
}
elseif($type == 1){
$forType = 'profile';
}
elseif($type == 2){
$forType = 'forum';
}
elseif($type == 3){
$forType = 'portal';
}
$sql="INSERT INTO comment(author, forType, forId, date, ip, content, extra, timeS)VALUES('$author', '$forType', '$forId', '$date', '$ip', '$content2', '$extra', '".time()."')";
$result=mysql_query($sql);
echo mysql_error();
echo 'Your post was added.';
// As the post was added, add 1 to their comment count
if($_SESSION['username'] !==$_GET['id']){
$sql1="UPDATE members SET hits = hits +1 WHERE username='$member'";
$result1=mysql_query($sql1);
}
}
else
{
echo 'Sorry but you can\'t post more than '.$set_amount.' times in 30 seconds. Try again later.';
}
} // End Function
Any ideas of how to get it working?