如何避免帖子重复提交?
我有一个允许用户粘贴输入的表单,就像 StackOverflow 上的那样。但如果用户知道我发送到服务器的格式,他们就可以继续向我发送请求。如何确保是真实用户发送请求而不是某种机器攻击插入信息?
I have a form that allows users to paste input, like on StackOverflow. But if users know the format I send to the server, they can keep sending requests to me. How can I ensure it is a real user sending a request instead of some kind of machine attack to insert information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有很多方法可以做到这一点,并且使用多种不同的东西是防止垃圾邮件的好主意。
stackoverflow 的做法(根据我的经验)是,如果发帖量异常,或者帖子很短,或者其他东西有点可疑,那么他们就会使用验证码。
您可以使用 cookie 来监控这一点,例如监控帖子之间的时间是某人正在发送垃圾邮件的一个很好的指标。同样,如果发布的消息的长度都大致相同,或者包含相同的网址/链接或其他内容,您也可以显示验证码来测试用户是否是人类。
There are a load of ways to do this and employing a large variety of different things is a good idea to protect against spam.
What stackoverflow does (from my experience) is if there is an abnormal amount of posting, or maybe the posts are very short, or something else is a bit suspicious then they use a capcha.
You can monitor this by using cookies, for instance monitoring the time between posts is a good indicator that someone is spamming. Similarly if the lengths of the messages posted are all about the same length, or include the same url/link or something you can also display a capcha to test if the user is a human or not.
您可以使用验证码。这可能是最常见的方法。
You can use a captcha. That's probably the most common approach.
有不同的技术可以让您或多或少地成功实现这一目标。使用验证码是许多网站使用的一种流行方式。
There are different techniques allowing you to achieve this with more or less success. Using a Captcha is one popular way used by many sites.