![](/img/trans.png)
[英]reCAPTCHA: Missing POST response for 'g-recaptcha-response'
[英]Sanitise and validate $_POST['g-recaptcha-response'] in recaptcha
如何在Recaptcha中清理和验证$_POST['g-recaptcha-response']
https://github.com/google/recaptcha/blob/master/examples/example-captcha.php#L72
看起来它提供了一个很长的字母数字字符_
和-
因此是否会使用strip_tags()
进行清理并检查是否只有字母数字字符_
和-
来验证?
您可以使用strip_tags
但这不能确保没有发送其他字符,例如@, #, ...
一种解决方案是使用preg_match
验证收到的字符串:
if (!preg_match('/^[\w-]*$/', $_POST['g-recaptcha-response'])) {
echo 'invalid captcha';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.