dswqz24846 2016-04-30 16:08
浏览 126
已采纳

在我的mysql数据库中限制每分钟的搜索次数

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
}
  • 写回答

1条回答 默认 最新

  • dongwo5589 2016-04-30 16:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)