开发者

Best way to avoid doing anything within X seconds before

Here, on Stack Overflow, if you try to comment a question/answer within 5 seconds from the last comment, it will give you an error.

What would be the best way of implement this?

开发者_StackOverflow

I've thought about storing in a variable the last time that action ocurred, and when it ocurrs again check the difference of time, and if it is valid, update the variable, if not, raise an error...


store the last time that the action ocurred in a variable, and when it ocurrs again check the difference of time, and if it is valid, update the variable, if not, raise an error..

:)


Another suggestion: You can store the info at client side(e.g. cookie), it will be faster to prompt the users. But you still need to check the timespan at server side, because things from client side can be cheated by naughty guys.


This is just a suggestion. I have not really tried this

Maybe you can hookup a method with SetTimeout in javascript whenever something happens say selected a value from dropdown. After the time has elapsed you can choose to attach a different method or enable the concerned control or something else as you feel suit.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜