Skip to main content

Codeigniter recaptcha form validation – Google recaptcha

Codeigniter recaptcha form validation – Google recaptcha

In this Post We Will Explain About is Codeigniter recaptcha form validation – Google recaptcha With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to codeigniter recaptcha form validationExample

In this post we will show you Best way to implement Google New reCaptcha using PHP Codeigniter, hear for integrate google recaptcha with codeigniter validationwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

First step : simple get an Google api key for your site from admin of the google, we must have google account simple ,and then go to this link below link and fill form some information like image

Also Read :  How to write SQL Sub Query in PHP with MySQLi

Step Second : copy simple generated and then api key like this image simple images.

and then put recaptcha simple input tag into your form data then put your simple api code into it, and then put api here link above the some same file like this

<div class="g-recaptcha"></div>

Step three : and then into your simple cI controller put this simple validation function

function live_captcha_validation() {
        $get_captcha = $this->input->post('g-recaptcha-response');
         $data_response = file_get_contents(" put here secret key here &response=" . $get_captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
        if ($data_response . 'success' == false) {
            return FALSE;
        } else {
            return TRUE;

or you can use curl if file_get_contents not supported by your hosting provider like this

Also Read :  AngularJS populate Dynamic Dependent dropdown in PHP

 function live_captcha_validation() {
        $valid_recaptcha = trim($this->input->post('g-recaptcha-response'));
        $userIp= $this->input->ip_address();
        $param_data = array(
            'secret' => "$secret",
            'response' => "$valid_recaptcha",
            'remoteip' =>"$userIp"

        $my_curl_live = curl_init();
        curl_setopt($my_curl_live, CURLOPT_URL, "");
        curl_setopt($my_curl_live, CURLOPT_POST, true);
        curl_setopt($my_curl_live, CURLOPT_POSTFIELDS, http_build_query($param_data));
        curl_setopt($my_curl_live, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($my_curl_live, CURLOPT_RETURNTRANSFER, true);
        $data_response = curl_exec($my_curl_live);
        $status= json_decode($data_response, true);
            return FALSE;
            return TRUE;

and Then put this simple validation some rule and text validation message

$this->form_validation->set_rules('g-recaptcha-response', 'here  live recaptcha validation', 'required|callback_live_captcha_validation');
$this->form_validation->set_message('live_captcha_validation', 'Please some check the here captcha form');


I hope you have Got What is Integrating Google’s reCaptcha in CodeIgniter’s form validation And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.

Web Developer

Hi, I’m Web developer, PHP is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]