2017-08-03 41 views
0

我又想出了新的谷歌验证码问题。 我有下面的代码视图文件:明明形式元素谷歌验证码实施中的“成功假”

 <p> 
     <div class="g-recaptcha" data-sitekey="MY_SITE_KEY"></div> 
    </p> 

上面的代码。 而在这之后, 在我的控制,我写了这个原则,

if ($this->form_validation->run() == TRUE) { 

     $recaptchaResponse = trim($this->input->post('g-recaptcha-response')); 
     $url = 'https://www.google.com/recaptcha/api/siteverify'; 
     $data = array(
      'secret' => 'MY_SECRET_KEY', 
      'response' => $recaptchaResponse 
     ); 
     $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 "<pre>"; print_r($captcha_success);die; 
     if ($captcha_success->success==false) { 
      echo "<p>You are a bot! Go away!</p>"; 
     } else if ($captcha_success->success==true) { 
      echo "<p>You are not not a bot!</p>"; 
     } 
     die; 
    } 

但它仍然不能正常工作形成了我。

其实,我已经注册了我的本地主机的网址与谷歌帐户,我有不同的密钥和网站的关键为本地和现场的。但是,当我尝试使用验证码时,live和local都给出了与以下相同的json输出。

{ 
    "success": false, 
    "error-codes": [ 
    "missing-input-response" 
    ] 
} 

请建议,如何克服这一点。

谢谢。

回答

0

您可能正在收到错误消息missing-input-response,因为您没有正确传递参数“response”。

您是否可以使用您用于调用验证码API的代码更新您的问题?

+0

嗨,谢谢你的回复。请看看我的更新编辑 – Punam

+0

谢谢你。我看不出任何明显的代码错误。 如果添加'echo $ this-> input-> post('g-recaptcha-response');'响应看起来有效吗?可能是响应正在通过$ this-> input-> post()过滤XSS。 – simondarke

+0

是的,它看起来也是有效的。不知道我在哪里得到错误。 我已经坚持了它,因为6至7小时.Didnt得到任何解决方案 – Punam