reCaptcha v2不会验证,无论如何

时间:2019-04-09 23:26:33

标签: recaptcha

我无法在网站上验证reCaptcha v2(复选框)。

这是站点:https://dev.newdawnmanuals.com/contact-us/

我的代码:

    <?php //FORM SUBMISSION PROCESS START
# reCaptcha keys
$siteKey = <my site key>;
$secretKey = <my secret key>;

  //Was there a reCAPTCHA response?
  if (isset($_POST['g-recaptcha-response'])) {
    $response = $_POST["g-recaptcha-response"];
    $captcha = $response;
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $data = array(
      'secret' => $secretKey,
      'response' => $response
    );
    $options = array(
      'http' => array (
        'method' => 'POST',
        'content' => http_build_query($data)
      )
    );
    $context  = stream_context_create($options);
    $verify = file_get_contents($url, false, $context);
    $captcha_success=json_decode($verify);

echo var_dump($verify); // **** TESTING ************************
echo var_dump($captcha_success); // **** TESTING ************************
  }

  if (!$captcha) {
    $display = "<p class=\"red\">Sorry, it appears you forgot to select the <strong>I'm not a robot</strong> checkbox.</p>";
  } else {
    $display = "<p class=\"red\">Sorry, the reCAPTCHA did not pass verification for some reason.</p>";
    } //FORM SUBMISSION PROCESS END ?>

echo var_dump($ verify);输出为: bool(false)

回声var_dump($ captcha_success); 输出为:NULL

据我所知,一切设置正确。我在其他站点上成功使用了Recaptcha v2,无法弄清为什么拒绝在此站点上进行验证。对于这个问题,我将不胜感激。因此,如果有人有任何想法或建议,我很想听听他们的想法。

0 个答案:

没有答案