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 Pakainfo.com – 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 :  jquery AJAX Dynamically Add remove PHP MySQLi

https://www.google.com/recaptcha/admin

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("https://www.google.com/recaptcha/api/sitemy_curl_live?secret=like 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 :  Bitcoin Altcoin Ethereum Cryptocurrency Exchange Script

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

        $my_curl_live = curl_init();
        curl_setopt($my_curl_live, CURLOPT_URL, "https://www.google.com/recaptcha/api/sitemy_curl_live");
        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);
        if(empty($status['success'])){
            return FALSE;
        }else{
            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');

Example

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(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *