简体   繁体   中英

Limit searches per minute in my mysql database

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM