Reputation: 375
I have a website offering a public database which can be searched by a simple form. I am using PDO for the queries.
I tried to Google, but I feel like I am missing the right keyword to help myself.
I would like to limit the searches every user can make to 5 searches per minute. What would be the right way of doing this with low effort? I don't need a high security solution, something to slow everything down a bit would help.
Is there a name for this? What can I search for?
// Create a session variable called something like this after you start the session:
$_SESSION['user_start'] = time();
// Then when they get to submitting the payment, just check whether they're within the 5 minute window
if (time() - $_SESSION['user_start'] < 300) { // 300 seconds = 5 minutes
// they're within the 5 minutes so save the details to the database
} else {
// sorry, you're out of time
unset($_SESSION['user_start']); // and unset any other session vars for this task
}
Upvotes: 0
Views: 81
Reputation: 1774
Actually you can't limit it from MySQL's settings. But you can avoid it with PHP. What you should do is set a SESSION per every user and set a parameter named "SearchTimes". Add 1 to it for every search if it's 5 stop the search operation. You can add some more Security to it with IP Address blocking.
Upvotes: 1