Google ReCaptcha 2.0 Client-Side Example [Working]

THIS CODE IS PLACED ON SERVER SIDE:
if(isset($_POST[‘g-recaptcha-response’])){
// Send data and get response
$cap = $_POST[‘g-recaptcha-response’];
$ch = curl_init(‘https://www.google.com/recaptcha/api/siteverify?secret=YOURSECRET=’.$cap);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “GET”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
}

if ($result[‘success’]==’false’) {
// What happens when the CAPTCHA was entered incorrectly
echo (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
//myerror(“Please Fill in User Name”);
$errorcheck=1;

} else {
// Your code here to handle a successful verification
}

Comments

Powered by Facebook Comments