douhu2131 2018-05-07 20:04
浏览 58
已采纳

reCAPTCHA只返回false,加载[关闭]时我得到ERR_EMPTY_RESPONSE

So... I decided to use reCAPTCHA on my website and it returns only false when it's JSON decoding, just like that:

$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";
}

It always writes "fail"

But when it's not json decoding:

$secretKey = "**************";
$responseKey = $_POST['g-recaptcha-response'];

$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$responseKey.'');
$_SESSION['response'] = $response;

It returns true: { "success": true, "challenge_ts": "2018-05-07T19:54:43Z", "hostname": "mywebsite.com" }

And second problem is that ERR_EMPTY_RESPONSE error, when I load action page. It occurs only when there's that reCAPTCHA stuff.

My 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>
  • 写回答

1条回答 默认 最新

  • doupeng8494 2018-05-07 23:36
    关注

    You have a typo?

    if($response->{'succes'} == 'true')
    

    It should be success. Also, it's a boolean in the response, not string, so you can't put 'true', use true without quotes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog