谷歌reCAPTCHA不使用codeigniter

时间:2017-06-13 07:34:25

标签: php codeigniter validation recaptcha

我正在尝试为我的网站联系表单设置google recaptcha。但它不适合我。请帮忙。

我的观看页面

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

控制器

public function send()
        {
          $this->load->library('curl'); 
          $this->load->library('session');
          $this->load->helper(array('form', 'url'));
                    $recaptchaResponse = trim($this->input->post('g-recaptcha-response'));
                    $userIp=$this->input->ip_address();
                    $secret='Secret key';
                    $url="https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response;=".$recaptchaResponse."&remoteip;=".$userIp;
                    $response = $this->curl->simple_get($url);
                    $status= json_decode($response, true);
        if($status['success']){  

        $config = array(        
                  'mailtype' => 'html',
                  'charset'  => 'utf-8',
                  'priority' => '1'
                   );


       $this->load->library('email',$config); 


                  $from_email = "yy@demo.com"; 
                  $to_email = "xx@demo.co.in"; 


        $message = '<html><body>';
        $message .= "<tr><td><strong>Email:</strong> </td><td>" . $this->input->post('email'). "</td></tr>";
        $message .= "<tr><td><strong>Message:</strong> </td><td>" . $this->input->post('message'). "</td></tr>";




         $this->email->from($from_email, 'demo'); 
         $this->email->to($to_email);
         $this->email->subject('Contact Info'); 
         $this->email->message($message); 
         $this->email->send()
         $this->session->set_flashdata('msg', 'Success..!');
         redirect($_SERVER['HTTP_REFERER']);


}else{
$this->session->set_flashdata('msg', 'Error...! Google Recaptcha UnSuccessful');
redirect($_SERVER['HTTP_REFERER']);
}
}

我总是收到flash消息

  

错误...! Google Recaptcha UnSuccessful

当我打印回复print_r($response); exit;

  

{&#34;成功&#34;:false,&#34;错误代码&#34;:[&#34;缺失 - 输入 - 响应&#34; ]}

0 个答案:

没有答案