Im adding a comment section to my forums and i want to add a delay, Maybe 30 seconds or so to stop people spamming along with a captcha .
Whats the best way to do this? Only way i can think is using cookies, any other suggestions?
When a user post their comment, write the current timestamp in a session and add it additional 30 seconds:
$_SESSION['postedTime'] = time() + 30;
When you want to check if 30 seconds are passed, get the current timestamp and compare them: if the current timestamp is bigger then one in session, then 30 seconds are passed:
$timestamp = time();
if($timestamp > $_SESSION['postedTime'])
{
// allow posting
}
else
{
// decline
}
For more security, you could insert user's IP + post timestamp in the database.
You could use PHP sessions to do something like this, but not sure how 'fool' proof it is.
The idea would be do something:
if(isset($_POST['cmdComment'])){
$_SESSION['comment_posted'] = time();
}
Then you could have a function say checkTime()
which you could put inside there to subtract the session value from the time it is now. If the difference is >= 30
seconds, then continue with the post and set the $_SESSION['comment_posted']
to the new time, otherwise ignore the post request.
A forum usually has members, well atleast I don't know any that do not have it.
Now if you post a comment I assume you put that in a table called something like Comment with an ID, POST_ID, USER_ID, MESSAGE, POST_DATETIME
Atleast thats how I would do it.
Now you have the datetime when the user last commented on the a certain post. Now you can query your database whether he or she can comment again