问题描述
我正在尝试将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}}