如何解决reCAPTCHA v3分数未返回
我正在尝试将Google reCaptcha实施到我的网站,这一切都可以,但是当尝试从响应中输出分数时,它总是返回NULL
if(!empty($this->request->data) && !empty($this->request->data['reToken'])){
$secretKey = "Key";
$response = file_get_contents(
"https://www.google.com/recaptcha/api/siteverify?secret=" . $secretKey . "&response=" . $this->request->data["reToken"] . "&remoteip=" . $_SERVER['REMOTE_ADDR']
);
if($this->request->data['username'] == "email"){
var_export($response);
var_export($response->score);
exit();
}
}
输出
'{ “成功”:是的, “ challenge_ts”:“ 2020-08-19T07:27:25Z”, “ hostname”:“主机名”, “得分”:0.9, “ action”:“ actionName” }' NULL
解决方法
您尝试访问字符串的属性。 <?php
....
$decoded = json_decode($response);
var_export($decoded->score);
....
?>
是JSON字符串。因此,您必须先对其进行解码。
{{1}}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。