Jump to content

Recommended Posts

im using a ajax form and basicly its easy to flood the form..

 

so what i did was type up this bit of code

<?php if (!isset($_REQUEST['Submit'])) {
//stop flooding
$query = "SELECT max(`time`) as t FROM messages WHERE reciever='$reciever' AND sender='$username'";
$res = mysql_query($query);
if(!$res) die("Query: $query\nError: ".mysql_error());
$lastMessageTime = mysql_num_rows($res) == 1 ? array_shift(mysql_fetch_array($res)) :
    0;
if ($lastMessageTime > 0 && $lastMessageTime < strtotime('+2 Minutes', $timestamp)) {
    $errors[] = 'Please wait 2 minutes between each message';
}?>

 

the thing is it does not work, no errors or anything but it does not show the error message and allows re submittance of the form, right away ?!?!?!

 

in the db time is stored as time();

 

Link to comment
https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/
Share on other sites

i have tried finding the error

<?php     //Get their private message count
    $sql = mysql_query("SELECT pm_count FROM users WHERE Username='$reciever'");
$res = mysql_query($sql);
   // $row = mysql_fetch_array($sql);
if (!$res)
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>QUERY FAIL: ";
   echo "<br/>$sql <br/>";
   die($errmsg);
}
?>

which gives the following output

QUERY FAIL:
Resource id #12
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #12' at line 1

butim confused by what Resource id #12 is

after running the following code

<?php if (!isset($_REQUEST['Submit'])) {
//stop flooding
$query = "SELECT max(unix_timestamp(`time`)) as t FROM messages WHERE reciever='$reciever' AND sender='$username'";
$res = mysql_query($query);
if (!$res)
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>QUERY FAIL: ";
   echo "<br/>$sql <br/>";
   die($errmsg);
}
$num = mysql_num_rows($res);
if (!$num)
{
   echo "<br/>QUERY FOUND NO DATA: ";
   echo "<br/>$sql <br/>";
}
else
{
   echo "<br/>QUERY FOUND $num ROWS OF DATA ";
   echo "<br/>$sql <br/>";
}
if(!$res) die("Query: $query\nError: ".mysql_error());
$lastMessageTime = mysql_num_rows($res) == 1 ? array_shift(mysql_fetch_array($res)) :
    0;
if ($lastMessageTime > 0 && $lastMessageTime < strtotime('+2 Minutes', $timestamp)) {
    $errors[] = 'Please wait 2 minutes between each message';
} ?>

 

it says that i have QUERY FOUND 1 ROWS OF DATA ... so why does it not apply the code if i submit the code twice within 10 seconds

As I stated before, no where in the code you posted that checks if it has been 2 minutes do you either run the insert statement or deny it.

 

You need to move the insert statement into that code for this to work. Leaving it outside of it will allow it to run no matter what. Bumping will not help as that is the answer.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.