Hi everyone,
I have a form in which I want to enable a type of flood control where a user can only submit x amount of (5) times in a given period (1 hour). I came up with this code which uses cookies and javascript to attempt to solve this issue.
The main concern would be to somehow delete/disable the cookie after 1 hour. After testing the above code I found that after 1 hour it would not let me submit again. Is there something wrong with the coding? Is there another way to do this using IP's and PHP? Using the cookie solution might not work if the user disables cookies.
I was trying out this php code to try to solve this issue in a different way using IP's and PHP:
where in table_data I have both the IP and date (in the form of 0000-00-00 00:00:00) stored after the submit button is pressed. This did not work. Also this code does not take into account how many times the user hits submit only takes into account the time.
Any suggestion with either the top code or the bottom code or a completely different solution would be greatly greatly appreciated.
Thanks
I have a form in which I want to enable a type of flood control where a user can only submit x amount of (5) times in a given period (1 hour). I came up with this code which uses cookies and javascript to attempt to solve this issue.
Code:
function AllowNoDups()
{
addtime = 60 * 60 * 1000 // 1 hour
expdate = new Date()
expdate.setTime(expdate.getTime() + addtime)
expdate = expdate.toGMTString()
var cookie_ls = document.cookie;
if (cookie_ls.indexOf(document.location) > -5)
{
alert("You can only submit 5 times in 1 hour. Please wait 1 hour before you submit again.");
return false;
}
else
{
document.cookie = window.location.href + " from " + document.referrer + "; path=/; expires=" + expdate;"";
return true;
};
};
The main concern would be to somehow delete/disable the cookie after 1 hour. After testing the above code I found that after 1 hour it would not let me submit again. Is there something wrong with the coding? Is there another way to do this using IP's and PHP? Using the cookie solution might not work if the user disables cookies.
I was trying out this php code to try to solve this issue in a different way using IP's and PHP:
PHP:
$c = "SELECT * from `table_data` WHERE ip = '".$_SERVER['REMOTE_ADDR']."'";
$c2 = mysql_query($c);
while($c3 = mysql_fetch_object($c2)) {
$difference = date() - $c3->date;
if($difference < 60) die('<u>ALERT:</u>Please wait 1 hour before you submit again<BR>');
} //end while
Any suggestion with either the top code or the bottom code or a completely different solution would be greatly greatly appreciated.
Thanks






