猿问

codeigniter php 中的 MISSING-INPUT-RESPONSE

我在 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”]}

任何人都可以告诉我我在代码中做错了什么,在此先感谢


慕桂英3389331
浏览 148回答 1
1回答

智慧大石

我认为方法应该是 GET 而不是 POST。请使用下面的代码来验证谷歌验证码。<?php&nbsp;public function validate_captcha() {&nbsp; $recaptcha = trim($this->input->post('g-recaptcha-response'));&nbsp; $userIp= $this->input->ip_address();&nbsp; $secret='6LcuEP4UAAAAAGa1zwXxGTV0r1fNHMZqnTGeN-c_';&nbsp; $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$recaptcha.'&remoteip='.$userIp);&nbsp; $responseData = json_decode($verifyResponse);&nbsp; &nbsp; if(!$responseData->success){&nbsp; &nbsp; &nbsp; &nbsp; echo "failed";&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; echo "success";&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答