runnerjp Posted April 7, 2009 Share Posted April 7, 2009 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(); Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/ Share on other sites More sharing options...
Zhadus Posted April 7, 2009 Share Posted April 7, 2009 How are you inserting it into the database originally? Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803573 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 like so <?php $timestamp = time(); $update = mysql_query("INSERT INTO messages (time,reciever, sender, subject, message) VALUES('$timestamp','$reciever', '$username', '$subject', '$message')") or die(mysql_error());?> Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803576 Share on other sites More sharing options...
premiso Posted April 7, 2009 Share Posted April 7, 2009 Do you do any checking before running that statement? If not, there is your answer. You need to do a check before you run the insert statement. Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803582 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 but it inserts as i can get the data and time by doing this <?php $time = $inbox['time']; $time1 = date("F j Y, g:i a", $time); echo $time1; ?> the problem is using it as the flood prevention Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803597 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 bmp Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803741 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803745 Share on other sites More sharing options...
9three Posted April 7, 2009 Share Posted April 7, 2009 You dont really need to know what #12 means. Just know that you have an SQL error $sql = mysql_query("SELECT pm_count FROM users WHERE Username='$reciever'"); $res = mysql_query($sql); Do you see the error? You are querying a query. Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803748 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 oh yes opps lol. i dont seem to be able to find why the flood control does not work :S any 1 see why Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803752 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803774 Share on other sites More sharing options...
runnerjp Posted April 7, 2009 Author Share Posted April 7, 2009 bmp Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-803865 Share on other sites More sharing options...
runnerjp Posted April 8, 2009 Author Share Posted April 8, 2009 bmp Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-804368 Share on other sites More sharing options...
premiso Posted April 8, 2009 Share Posted April 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/152998-flood-protection-on-a-form/#findComment-804515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.