Skip to content

Jirateep12/recaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 

Repository files navigation

๐Ÿฒ requirement

  • client side key
  • Server side key

๐Ÿ˜บ apply at

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

Load the JavaScript API with your client-side key.

<script async src="https://www.google.com/recaptcha/api.js?render=(client side key)></script>

๐Ÿฎ reCAPTCHA v2

Box code to confirm, paste it in the desired location.

<div class="g-recaptcha" data-sitekey="(client side key)"></div>

๐ŸŽ reCAPTCHA v3

Add an attribute to your button.

<button class="g-recaptcha" data-sitekey="(client side key)" data-callback="onSubmit" data-action="submit">Submit</button>

Server side code (php) / (javascript)

// php
<?php
define("secretkey", "Server side key");
$result = recaptcha();
if ($result["success"]) {
    // Added what to do when verified correctly
} else {
    // Added what to do when incorrect identity verification
}

function recaptcha() {
	$options = [
		"secret" => secretkey,
		"response" => filter_input(INPUT_POST, "g-recaptcha-response"),
		"remoteip" => $_SERVER["REMOTE_ADDR"]
	];
	$url = "https://www.google.com/recaptcha/api/siteverify?" . http_build_query($options);
	$result = json_decode(file_get_contents($url), true);
	return $result;
}
?>
// javascript
(() => {
	grecaptcha.ready(function () {
		grecaptcha.execute("Server side key", { action: "submit" }).then(function (token) {
			console.log(token);
		});
	});
})();

๐Ÿ™ Thank Ref : reCAPTCHA v2 | reCAPTCHA v3

Releases

No releases published

Packages

No packages published