Reputation: 1685
My apologize if I missing something here but now I am looking for php code that limit for post after a specified of period. so example that after click the send button it will be able to send again after x time long, I would appreciate if anyone who gives instructions, pointers, sample urls or some codes would be help me, thanks in advance...
Upvotes: 1
Views: 105
Reputation: 59002
Well, you need to store the last time someone sent a POST
somewhere. You have several options:
In a cookie - This is not as safe as the other options, as the client can manipulate / remove the cookie.
In server session ($_SESSION) - This is the easiest way, since you don't need to track a specific client by IP or something like that.
In a database - This is the most flexible way, you can easily see and manage your clients.
Each time when someone makes a POST, check in your storage when they last did a post, and deny it if it was to soon.
You could also do this on client side, using javascript. However, that's not as safe as the client can disable/manipulate it.
Upvotes: 3
Reputation: 3887
One technique is to disable the submit button using javascript like so:
<form id="myform" name="myform" onsubmit="disableForATime();">
<!-- form elements -->
<input type="submit" value="Submit" id="submitButton" name="submitButton"/>
</form>
<script type="text/javascript">
function disableForATime(){
document.getElementById('submitButton').setAttribute('enabled', false);
setTimeout(enableSubmit, 5000); //modify 5000 to be the number of milliseconds you would like to disable the button for.
}
function enableSubmit(){
document.getElementById('submitButton').setAttribute('enabled', true);
}
</script>
Upvotes: 1