简体   繁体   English

reCaptcha V2未在php中返回响应

[英]reCaptcha V2 not returning a response in php

I have implemented the recapture code on the my html form with no problem. 我已经在我的html表单上实现了捕获代码,没有问题。

I have the java script reference located in the header. 我在标题中有Java脚本参考。 I get a result for the g-recaptcha-response but when i try and verify it i get no result, i get nothing back, no error, nothing. 我得到g-recaptcha-response的结果,但是当我尝试验证它没有结果时,我什么也没回来,没有错误,什么也没有。 I have checked my site and secret keys are correct. 我已经检查了我的网站,并且密钥正确。 I have also put the $resp in the $status to see what the verified response is from google and it always shows as empty. 我还将$ resp放在$ status中,以查看来自Google的经过验证的响应,并且该响应始终显示为空。 I am unable to figure out what i have done wrong. 我无法弄清楚我做错了什么。

<div class="g-recaptcha" data-sitekey="MY.SITE.KEY"></div>
                      <br/>

                    <button  name="submit" type="submit">Submit Registration Form</button>

    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
    //your site secret key
    $secret = 'MY.SECRET.KEY';
    //get verify response data
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
    $resp = json_decode($verifyResponse);

    if ($resp->success==false) 
    {
        $proceed = false;
        $status .= "You entered the ReCaptcha field incorrectly!".$resp."<br />";
    }

It seems you are missing a curly brace. 看来您缺少花括号。

if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {        
$secret = 'MY.SECRET.KEY';
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$resp = json_decode($verifyResponse);

if ($resp->success== true) 
{
  //Do something
}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM