繁体   English   中英

在Recaptcha中清理并验证$ _POST ['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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM