在表单验证中仅输入一次Recaptcha失败? [英] Entering recaptcha only once on form validation fail?

查看:161
本文介绍了在表单验证中仅输入一次Recaptcha失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,该表单的末尾有一些字段和一个recaptcha代码。

I have a form which has a few fields and a recaptcha code at the end.

当用户提交表单时,recaptcha字段与服务器端(PHP)上的其他字段。如果任何字段无效,则会将用户重定向到具有错误的相同表单。

When the user submits the form, the recaptcha field is validated along with the other fields on server side (PHP). If the any of the fields are invalid, the user is redirected to the same form with errors.

但是,问题是:用户必须再次输入recatpcha。

However, the problem is : The user has to enter the recatpcha again.

如果表单验证失败但验证码验证成功,有什么办法不能要求用户再次输入Recaptcha吗?

Is there any way I can NOT ask the user to enter the recaptcha again if the form validation fails but captcha validation is successful ?

推荐答案

当然可以。您可以将Recaptcha的验证成功存储到会话(或Cookie或数据库)中,然后在指示存在的情况下隐藏Recaptcha。在服务器端,您只需要检查Recaptcha是否正确或指示是否有效。

Sure there is. You could store the validation success of the recaptcha into the session (or a cookie, or a database) and then hide the recaptcha if the indication is there. On the serverside you simply have to check if either the recaptcha is correct or the indication is valid.

您还必须确保只能使用有效的Recaptcha cookie。一次,因为如果不是这样,垃圾邮件发送者可以简单地一遍又一遍地发送cookie信息并解决该重新捕获问题。

You also have to make sure that a valid recaptcha cookie can only be used once, because if not the spammer can simply sent the cookie information over and over again and work around the recaptcha.

我的想法是将会话中的时间戳存储在键,例如 recaptcha_success,然后检查时间戳记是否不超过几分钟(最适合您的需求)。如果不是,请通过不再次验证来解决该验证码。如果该表格有效,请删除密钥,以便下次用户要使用该表格时,他必须再次输入该Recaptcha。

My idea is to store a timestamp within the session under a key like "recaptcha_success" and then check if the timestamp is not older than a few minutes (whatever fits your needs). If it's not, work around the recaptcha by not validating it again. If the form is valid, remove the key so the next time the user wants to use the form he has to enter the recaptcha again.

这篇关于在表单验证中仅输入一次Recaptcha失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆