【问题标题】:reCaptcha V2 not returning a response in phpreCaptcha V2 未在 php 中返回响应
【发布时间】:2017-07-13 13:15:15
【问题描述】:

我已经在我的 html 表单上实现了重新捕获代码,没有问题。

我在标头中有 java 脚本参考。我得到了 g-recaptcha-response 的结果,但是当我尝试验证它时,我没有得到任何结果,我什么也得不到,没有错误,什么也没有。我检查了我的网站并且密钥是正确的。我还将 $resp 放在 $status 中,以查看经过验证的响应来自 google,它始终显示为空。我无法弄清楚我做错了什么。

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

【问题讨论】:

    标签: php recaptcha


    【解决方案1】:

    您似乎缺少一个花括号。

    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
    }}
    

    【讨论】:

      猜你喜欢
      • 2015-11-05
      • 1970-01-01
      • 2019-01-15
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2017-10-22
      相关资源
      最近更新 更多