PHP code example of mehdibo / codeigniter-recaptcha

1. Go to this page and download the library: Download mehdibo/codeigniter-recaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mehdibo / codeigniter-recaptcha example snippets


$this->recaptcha->set_keys('site_key', 'secret_key');

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

$recaptcha = new Recaptcha($config);

$recaptcha->method_name();

$this->recaptcha->set_parameter('parameter_name', 'value');

$this->recaptcha->set_parameters($params);

$this->recaptcha->set_parameter('theme', 'dark');

$this->recaptcha->create_box($attributes)

$attributes = array(
    'class' => 're-box',
    'id' => 'an-id'
)

$this->recaptcha->is_valid($response, $ip)



class Form extends CI_Controller {

	public function index()
	{
		/*
		 Load the reCAPTCHA library.
		 You can pass the keys here by passing an array to the class.
		 Check the "Setting the keys" section for more details
		*/
		$recaptcha = new Recaptcha();

		/*
		 Create the reCAPTCHA box.
		 You can pass an array of attributes to this method.
		 Check the "Creating the reCAPTCHA box" section for more details
		*/
		$box = $recaptcha->create_box();

		// Check if the form is submitted
		if($this->input->post('action') === 'submit')
		{
			/*
			 Check if the reCAPTCHA was solved
			 You can pass arguments to the `is_valid` method,
			 but it should work fine without any.
			 Check the "Validating the reCAPTCHA" section for more details
			*/
			$is_valid =$recaptcha->is_valid();

			if($is_valid['success'])
			{
				echo "reCAPTCHA solved";
			}
			else
			{
				echo "reCAPTCHA not solved/an error occured";
			}
		}

		$this->load->view('form', ['recaptcha' => $box]);
	}



class Form extends CI_Controller {

	public function index()
	{
		/*
		 Load the reCAPTCHA library.
		 You can pass the keys here by passing an array to the loader.
		 Check the "Setting the keys" section for more details
		*/
		$this->load->library('recaptcha');

		/*
		 Create the reCAPTCHA box.
		 You can pass an array of attributes to this method.
		 Check the "Creating the reCAPTCHA box" section for more details
		*/
		$recaptcha = $this->recaptcha->create_box();

		// Check if the form is submitted
		if($this->input->post('action') === 'submit')
		{
			/*
			 Check if the reCAPTCHA was solved
			 You can pass arguments to the `is_valid` method,
			 but it should work fine without any.
			 Check the "Validating the reCAPTCHA" section for more details
			*/
			$is_valid = $this->recaptcha->is_valid();

			if($is_valid['success'])
			{
				echo "reCAPTCHA solved";
			}
			else
			{
				echo "reCAPTCHA not solved/an error occured";
			}
		}

		$this->load->view('form', ['recaptcha' => $recaptcha]);
	}