我在codeigniter中创建了一个登录页面,但我面临的问题是我是一个新的codeigniter,我不能在那里添加reChaptcha,但我尽力做到最好,但最后它不起作用 . 我阅读谷歌reChaptcha的文档,但我不明白,我如何使其功能?

当用户登录请求reChaptcha如果reChaptcha解决然后成功登录其他错误时我如何做 .

我的代码如下,请帮忙...

view

<form action="<?php echo base_url('auth/login') ?>" method="post">
      <div class="form-group has-feedback">
        <input type="email" class="form-control" value="mail@domain.com" name="email" id="email" placeholder="Email" autocomplete="off">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" value="Asdfghjkl" class="form-control" name="password" id="password" placeholder="Password" autocomplete="off">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="g-recaptcha" data-sitekey="6LfAzH8UAAAAAPq9IBqElP4Z7x6rjc880PbYhaJ_"></div> 
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox"> Remember Me
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit" class="g-recaptcha btn btn-primary btn-block btn-flat" data-sitekey="my site key here" data-callback="YourOnSubmitFn">Sign In</button>
        </div>
        <!-- /.col -->
      </div>
    </form>

Controller

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Auth extends Admin_Controller 
    {

	public function __construct()
	{
		parent::__construct();

		$this->load->model('model_auth');
	}

	/* 
		Check if the login form is submitted, and validates the user credential
		If not submitted it redirects to the login page
	*/
	public function login()
	{

		$this->logged_in();

		$this->form_validation->set_rules('email', 'Email', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('g-recaptcha-response','Captcha Challenge','required');


         $recaptcha_headers = array('Content-Type' => 'application/json');
				$recaptcha_fields = array(
						'secret'   => "MY CODE HERE",
						'response' => $this->input->post('g-recaptcha-response'),
						'remoteip' => $_SERVER['REMOTE_ADDR']
				);

				$this->load->library('PHPRequests');
				$response = Requests::post("https://www.google.com/recaptcha/api/siteverify", array(), $recaptcha_fields);
				$recaptcha_post_body = json_decode($response->body, true); 
				
				

				
        if ($this->form_validation->run() == TRUE) {
            // true case
           	$email_exists = $this->model_auth->check_email($this->input->post('email'));

           	if($email_exists == TRUE) {
           		$login = $this->model_auth->login($this->input->post('email'), $this->input->post('password'));

           		if($login) {

           			$logged_in_sess = array(
           				'id' => $login['id'],
				        'username'  => $login['username'],
				        'logged_in' => TRUE
					);

					$this->session->set_userdata($logged_in_sess);
           			redirect('dashboard', 'refresh');
           		}
           		else {
           			$this->data['errors'] = 'Incorrect username/password combination';
           			$this->load->view('login', $this->data);
           		}
           	}
           	else {
           		$this->data['errors'] = 'Email does not exists';

           		$this->load->view('login', $this->data);
           	}	
        }
        else {
            // false case
            $this->load->view('login');
        }	
	}

	/*
		clears the session and redirects to login page
	*/
	public function logout()
	{
		$this->session->sess_destroy();
		redirect('auth/login', 'refresh');
	}

    }