Php reCAPTCHA仅返回false,并且在加载时收到ERR\u EMPTY\u响应
所以。。。我决定在我的网站上使用reCAPTCHA,当它是JSON解码时,它只返回false,如下所示:Php reCAPTCHA仅返回false,并且在加载时收到ERR\u EMPTY\u响应,php,html,recaptcha,Php,Html,Recaptcha,所以。。。我决定在我的网站上使用reCAPTCHA,当它是JSON解码时,它只返回false,如下所示: $secretKey = "***********"; $responseKey = $_POST['g-recaptcha-response']; $url = 'https://www.google.com/recaptcha/api/siteverify? secret='.$secretKey.'&response='.$responseKey.'';
$secretKey = "***********";
$responseKey = $_POST['g-recaptcha-response'];
$url = 'https://www.google.com/recaptcha/api/siteverify?
secret='.$secretKey.'&response='.$responseKey.'';
$response = file_get_contents($url);
$response = json_decode($response);
if ($response->{'succes'} == 'true') {
$_SESSION['response'] = "succes";
} else {
$_SESSION['response'] = "fail";
}
它总是写失败
但如果不是json解码:
$secretKey = "**************";
$responseKey = $_POST['g-recaptcha-response'];
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$responseKey.'');
$_SESSION['response'] = $response;
它返回true:{success:true,challenge_ts:2018-05-07T19:54:43Z,主机名:mywebsite.com}
第二个问题是,当我加载操作页面时,ERR_EMPTY_响应错误。只有当有“重述”的东西时才会发生
我的帖子:
<form method="post" id="form" class="form" action="action/logreg.php">
<input name="name" class="name" placeholder="Jméno" type="text" />
<input name="surname" class="surname" placeholder="Přijmení" type="text"/>
<input name="email" class="email" placeholder="E-mail" type="email" />
<input name="psswd" class="psswd" placeholder="Heslo" type="password"/>
<button type="submit"name="regBtn" class="regBtn">Registrovat</button>
<div class="g-recaptcha" data-sitekey="*********"></div>
</form>
你有打字错误吗
if($response->{'succes'} == 'true')
这应该是成功。
另外,它在响应中是一个布尔值,而不是字符串,因此您不能输入'true',使用不带引号的true。可能与$response->{'success'}重复?是的,就是这样。非常感谢,但有时仍然会出现ERR_EMPTY_响应错误。