通过IP地址和时间间隔限制表单提交速率

发布于 2024-12-10 20:15:01 字数 450 浏览 0 评论 0原文

在之前关于如何限制一小时内提交表单的次数的问题上,有人这样说:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有深☉意 2024-12-17 20:15:01

您的查询计算“mysql_table”中存在多少条记录

select count(*) from mysql_table

,并将该计数限制为具有 ip=user_ip

where ip='$ip'

且时间戳(存储记录时间的日期/时间列)大于表示“一小时前”的时间的记录

timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR)

(请记住每次插入记录时,您可能会将时间戳字段设置为当前日期/时间)。
您要做的就是将此结果与允许的最大值进行比较,并确定它是否好。

Your query counts how many records are present in "mysql_table"

select count(*) from mysql_table

and limit that count to records having ip=user_ip

where ip='$ip'

and timestamp (the date/time column in which recording time is stored) is greater than time representing "one hour ago"

timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR)

(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文