【问题标题】:MISSING-INPUT-RESPONSE recaptcha error in codeigniter phpcodeigniter php中的MISSING-INPUT-RESPONSE recaptcha错误
【发布时间】:2020-09-17 22:38:02
【问题描述】:

我已经在 codeigniter 中为我的表单创建了 recaptcha,recaptcha 函数在我的控制器中如下所示:

public function validate_captcha() {
          $recaptcha = trim($this->input->post('g-recaptcha-response'));
          $userIp= $this->input->ip_address();
          $secret='6LcuEP4UAAAAAGa1zwXxGTV0r1fNHMZqnTGeN-c_';
          
          $secretdata = array(
              'secret' => "$secret",
              'response' => "$recaptcha",
              'remoteip' =>"$userIp"
          );

          $verify = curl_init();
          curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
          curl_setopt($verify, CURLOPT_POST, true);
          curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($secretdata));
          curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
          $response = curl_exec($verify);
          $status= json_decode($response, true);
          
          if(empty($status['success'])){
              return FALSE;
          }else{
              return TRUE;
          }
      }

现在的问题是这给了我以下错误:

{"SUCCESS":FALSE,"ERROR-CODES":["MISSING-INPUT-RESPONSE"]}

谁能告诉我我的代码做错了什么,提前谢谢

【问题讨论】:

    标签: php codeigniter error-handling recaptcha


    【解决方案1】:

    我认为 Method 应该是 GET 而不是 POST。

    请使用以下代码验证 Google 验证码。

    <?php 
    
    public function validate_captcha() {
      $recaptcha = trim($this->input->post('g-recaptcha-response'));
      $userIp= $this->input->ip_address();
      $secret='6LcuEP4UAAAAAGa1zwXxGTV0r1fNHMZqnTGeN-c_';
    
      $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$recaptcha.'&remoteip='.$userIp);
      $responseData = json_decode($verifyResponse);
        if(!$responseData->success){
            echo "failed";
        }else{
            echo "success";
        }
    
    }
    

    【讨论】:

    • 让我检查一下兄弟
    猜你喜欢
    • 2017-10-22
    • 2015-10-05
    • 2020-09-17
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2012-02-28
    相关资源
    最近更新 更多