reCAPTCHA returns 仅为假,我在加载时得到 ERR_EMPTY_RESPONSE
reCAPTCHA returns only false and I'm getting ERR_EMPTY_RESPONSE while loading
所以...我决定在我的网站上使用 reCAPTCHA,它 returns 只有在 JSON 解码时才为假,就像那样:
$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";
}
它总是写"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;
它returns正确:{ "success": true, "challenge_ts": "2018-05-07T19:54:43Z", "hostname": "mywebsite.com" }
第二个问题是 ERR_EMPTY_RESPONSE 错误,当我加载操作页面时。只有当有 reCAPTCHA 的东西时才会发生。
我的post:
<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。
所以...我决定在我的网站上使用 reCAPTCHA,它 returns 只有在 JSON 解码时才为假,就像那样:
$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";
}
它总是写"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;
它returns正确:{ "success": true, "challenge_ts": "2018-05-07T19:54:43Z", "hostname": "mywebsite.com" }
第二个问题是 ERR_EMPTY_RESPONSE 错误,当我加载操作页面时。只有当有 reCAPTCHA 的东西时才会发生。
我的post:
<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。