Created
January 29, 2018 07:30
-
-
Save RakibSiddiquee/76d316250803712eb3e334d0ca7d8178 to your computer and use it in GitHub Desktop.
Google recapcha v2 implementation in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//To start using reCAPTCHA, you need to sign up for an API key pair for your site from https://www.google.com/recaptcha/admin#list | |
$siteKey = "6LcqlUAUAAAAAFqZqFzhtEHApepRVPtv-Xynkub9"; | |
$secretKey = "6LcqlUAUAAAAADt1b9okVcSrgC0461J9NyTzNqlY"; | |
$gres = $_POST['g-recaptcha-response']; | |
$ip = $_SERVER['REMOTE_ADDR']; | |
$suc = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$gres.'&remoteip='.$ip); | |
$res = json_decode($suc); | |
if($res->success){ | |
echo 'You are successfully submitted!'; | |
}else{ | |
?> | |
<html> | |
<head> | |
<title>reCAPTCHA demo: Simple page</title> | |
<script src="https://www.google.com/recaptcha/api.js" async defer></script> | |
</head> | |
<body> | |
<form action="recapcha.php" method="POST"> | |
<div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>"></div> | |
<br/> | |
<input type="submit" value="Submit"> | |
</form> | |
</body> | |
</html> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment