How to add Google reCAPTCHA in CodeIgniter

Hi guys today, After a long time I am back with a new tutorial. Today I am going to show you about Google reCAPTCHA using in CodeIgniter. If you want to use Google reCAPTCHA in CodeIgniter then this tutorial is perfect to help you. I hope you know what is ReCaptcha? If you don't know that we are starting from the first.

What is Google reCAPTCHA?

Google reCAPTCHA is a service offered by Google which verifies a user human or robot. Google reCAPTCHA show some images and give hint in text and ask users to select appropriate images on the subject. If users select perfectly then google verified that the user is not a robot.

Why should use  Google reCAPTCHA?

You should use  Google reCAPTCHA to prevent robots access to your sensitive pages like login page, registration page, reset form page etc. If you use  Google reCAPTCHA on your website robots could not be registered and couldn't be trying for login.  Google reCAPTCHA also help you to prevent Brute-force attack on your website. Now we are going to the main part of this tutorial.

How to use  Google reCAPTCHA in CodeIgniter?

For using the Google reCAPTCHA you have to go Google reCAPCTHA website and click in My reCAPTCHA from the right top from the website. Then type label click select a version between reCAPTCHA v2 and reCAPCTHA v3 and then type domains which you want and click accept terms and then finally click Register button. 

Now you will be entered in the main page of Google reCAPTCHA page which you can find the necessary items which help you to use Google reCAPTCHA. You will find Site key and Secret key on the page.

Now click on  Step 1: Client side integration to integrate reCAPTCHA with your website. 

<script src=''></script>

Add this code into your webpage footer and then go to the back-end script view page and the snippet into your view page.

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

Change site key as your key which is provided by google next go to your controller and start validating in the controller after form validation. Now paste the code just after form validation of this code-

    $response = $this->input->post('g-recaptcha-response');
        $verifyResponse = file_get_contents(''.$secret.'&response='.$response);
        $responseData = json_decode($verifyResponse);

    $this->session->set_userdata(array('message'=>'reCAPTCHA input is not valid.'));

    redirect($_SERVER['HTTP_REFERER'], 'refresh');


replace secret key from Google reCAPTCHA page and then start using. Your Google reCAPTCHA is now ready to use.

This is an easy way to use Google reCAPTCHA and start using today. If you like this tutorial please share this with your friends.

Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Need Assistance?

I'm Sajjad Hossain, working on web application development since 2012. Do you need assistance on your project? or are you stuck with problems? I am available to help you.
If you want to contact with me ping me at -


We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy