How to setup the google reCAPTCHA

STEP :-1

Create reCAPTCHA API keys from recaptcha admin.

https://www.google.com/recaptcha/admin?hl=en#list

STEP :-2 [Client Side]

Add the recaptcha api js and render explicit.

https://www.google.com/recaptcha/api.js?onload=init_google_captcha&render=explicit

Put below code in bottom of page:

function init_google_captcha() {
	if( jQuery('#home-contact-captcha').length>0 ) {
		captcha_home_contact = grecaptcha.render('home-contact-captcha',{
		 'sitekey' : '6LeJTT8UAAAAABjGeM6FpNutjh9_4t5sTixpnpdq',
		 'theme' : 'light'
		});
	}
}

 

STEP :-3 [Server Side]

While submit the form you got the post variable with name “g-recaptcha-response”.

For verify the response use the below API_URL.
https://www.google.com/recaptcha/api/siteverify

You have to add the secret, response, remoteip vars with URL and post the data.

-Sample snippet

$reCAPTCHA_site_key = reCAPTCHA_SITE_KEY;
$reCAPTCHA_secret_key = reCAPTCHA_SECRET_KEY;

if( $this->input->post('g-recaptcha-response') ) {
	$recaptcha_response = $this->input->post('g-recaptcha-response');
	$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $reCAPTCHA_secret_key . "&response=" . $recaptcha_response . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
	$response = json_decode($response);
	if ( isset($response->success) && $response->success == 1 ) {
		//validate successfully.
	}
}

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

Advertisements

Best Web Development Tutorials For Beginners

W3schools

https://www.w3schools.com

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.

TutorialsPoint

https://www.tutorialspoint.com/

Free tutorials and reference manuals with examples for Kubernetes, Spring JDBC, Java Concurrency, Gerrit, Spring AOP, Spring MVC, Apache Solr, Excel Power View, Sencha Touch, Tex Commands, Agile Testing, Apache Tajo, C++ Library, MariaDB, SAP QM, SAP SOLMAN, SAP SCM, MS Access, KoaJS, OAuth2.0, Scrapy, SAP CCA, SAP PM, SAPUI5, Cognos, Internet of Things, Rural Marketing, Trampolining, Golf, Angular2, Framework7, Arduino, CherryPy, Firebase, SAP C4C, SAP Dashboard, SAP PI, ExpressJS, Design Thinking, Internet Security, PyGTK, Apache Drill, Excel Charts, Elastic Search, Computer Security, Extreme Programming, Behavior Driven Development, Conversion Rate Optimization, SAP Basis, Business Law, Kanban, Erlang, SAP Payroll, ASP.Net WP, PouchDB, MFC, SAP HR, Yii, Clojure, Aurelia, CoffeeScript, CPanel, Laravel, SAP Webi, MS SQL Server, pinterest, Indian Polity, Windows10, Teradata

CSS Tricks

https://css-tricks.com

Tips, Tricks, and Techniques on using Cascading Style Sheets.

Codrops

https://tympanus.net/codrops/

Codrops is a web design and development blog that publishes articles and tutorials about the latest web trends, techniques and new possibilities.

GitHub

https://github.com/

GitHub is a web-based Git or version control repository and Internet hosting service. It is mostly used for code. It offers all of the distributed version control and source code management functionality of Git as well as adding its own features.

Stack Overflow

https://stackoverflow.com/

Stack Overflow is the largest online community for programmers to learn, share their knowledge, and advance their careers.

Blog at WordPress.com.

Up ↑