Google Recaptcha is one of the most effective ways of fighting automated spam today. Below we will see how we can integrate google recaptcha on a codeigniter website in just three steps :
- Go to https://www.google.com/recaptcha/admin and sign up for reCAPTCHA API keys for your website. The keys automatically work on http://localhost or http://127.0.0.1. There are two reCAPTCHA keys: Site Key and Secret Key. Site Key would be used in the front-end public form and Secret Key will be used in the back-end code (php, ruby etc).
- Open the view page of your codeigniter where the form is located. Let’s assume we have a form to collect some comments from end user similar to below page:
We only added 2 lines here, highlighted in bold. If your key is correct, you should be seeing google reCAPTCHA widget before submit while viewing the form.
Now we will add few lines in the controller/model code in the back end.
- Go to the controller comments/create and add the lines as below where form validation is being performed
That’s it. Let us know using the comments below if any issues !!!