dstt1818 2016-06-22 19:49
浏览 28
已采纳

存储服务器端倒计时变量

I am currently working on a function where there is a countdown before you can perform the same action again.

Meaning: perform action, then you have to wait 30 seconds before you can perform the action again.

My problem is: how do I make sure the user cannot just re-enter the page to reset the countdown if I were to use a JS function?

I do have a MySQL database if that helps.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzai9405 2016-06-22 19:59
    关注

    The only way to avoid the user to reset or cheat the countdown is to implement it in the server side.

    The issue is to have some way to identify the user, so he cannot just reset the cache, cookie or equivalent. There is not a general solution for that, but usually, problems which require countdown have related identification.

    As an example, in the past I implemented a solution like that for user login: when the password is wrong, he cannot re-enter a new password for a while. In this case, the identification is clear: the user login.

    Of course, if security is not a big issue, there are plenty of simpler solutions: timers, cookies, etc.

    The solution

    On any Operation-try from the user, perform:

    • Check in the database, if any user already tried a short time ago with the same identification (login?)
    • If yes, just return the error message.
    • If not, perform the operation
    • Save the new try with a time-stamp in the database, so a new try is not possible until the specified time has passed..
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办