【发布时间】:2020-08-19 15:46:36
【问题描述】:
我正在尝试在我的网站上实现 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", “主机名”:“主机名”, “分数”:0.9, “动作”:“动作名称” }' 空
【问题讨论】:
-
它是 JSON - 即它是文本。您需要先对其进行解码,然后才能像对象一样使用它