通过IP地址和时间间隔限制表单提交速率
在之前关于如何限制一小时内提交表单的次数的问题上,有人这样说:
select count(*) from mysql_table where uid='$uid' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR););
这似乎可行,但我不知道如何实现。首先我想用IP替换uid:
select count(*) from mysql_table where ip='$ip' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR););
但之后我不太确定时间戳如何> (DATE_ADD(now(), 间隔 - 1 小时););实际上有效。我确实为每个帖子提交了时间戳,但我不知道其余部分实际上是如何工作的,有人可以向我解释一下吗?
On a previous question about how I could limit the amount of times a form is submitted in an hour, someone said this:
select count(*) from mysql_table where uid='$uid' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR););
That seem's like it would work, but I have no idea how. First I'd like to replace uid with IP:
select count(*) from mysql_table where ip='$ip' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR););
But after that I'm not quite sure how the timestamp > (DATE_ADD(now(), INTERVAL - 1 HOUR);); actually works. I do submit a timestamp with each post, but I don't know how the rest actually works, can someone explain it to me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的查询计算“mysql_table”中存在多少条记录
,并将该计数限制为具有 ip=user_ip
且时间戳(存储记录时间的日期/时间列)大于表示“一小时前”的时间的记录
(请记住每次插入记录时,您可能会将时间戳字段设置为当前日期/时间)。
您要做的就是将此结果与允许的最大值进行比较,并确定它是否好。
Your query counts how many records are present in "mysql_table"
and limit that count to records having ip=user_ip
and timestamp (the date/time column in which recording time is stored) is greater than time representing "one hour ago"
(remember that every time you insert a record, you probably set timestamp field to current date/time).
What you have to do is comparing this result with maximum allowed and decide if it's good or not.