Reputation: 15959
Im making forum software. Now i want to add anti-flood. So when a post gets posted, a date("j-n-Y H:i:s")
gets put in the table. Now i want a max of 4 posts per minute, or 15 seconds between each post. What is the best way to check that?
Upvotes: 0
Views: 245
Reputation: 33163
You can get the time 15 seconds ago with
$time = date( 'Y-m-d H:i:s', time() - 15 );
Then find the number of posts made by this user after that time. If the count is more than 0, discard the post.
SELECT COUNT(*) FROM posts WHERE user_id = $userId AND posted >= '$time'
If you'd rather have the 4 posts/minute rule, do the same thing but with 60 seconds and discard if the count is more than 4.
$time = date( 'Y-m-d H:i:s', time() - 60 );
SELECT COUNT(*) FROM posts WHERE user_id = $userId AND posted >= '$time'
Upvotes: 2