About

Contact Form

Name

Email *

Message *

DMCA

Friday, 30 November 2018

thumbnail

reCAPTCHA V3 Example in PHP


<!DOCTYPE html>
<html>
<head>
<title>reCaptcha V3 example php</title>
</head>
<body>

<?php
## reCAPTCHA V3 key define ##
#client-side
define('RECAPTCHA_SITE_KEY','reCAPTCHA_site_key'); // define here reCAPTCHA_site_key
#server-side
define('RECAPTCHA_SECRET_KEY','reCAPTCHA_secret_key'); // define here reCAPTCHA_secret_key

class Captcha{
public function getCaptcha($SecretKey){
$Resposta=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".RECAPTCHA_SECRET_KEY."&response={$SecretKey}");
$Retorno=json_decode($Resposta);
return $Retorno;
}
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

//echo "<pre>"; print_r($_REQUEST); echo "</pre>";

$ObjCaptcha = new Captcha();
$Retorno = $ObjCaptcha->getCaptcha($_POST['g-recaptcha-response']);

//echo "<pre>"; print_r($Retorno); echo "</pre>";

if($Retorno->success){
echo '<p style="color: #0a860a;">CAPTCHA was completed successfully!</p>';
}else{
echo '<p style="color: #f80808;">reCAPTCHA error: Check to make sure your keys match the registered domain and are in the correct locations.<br> You may also want to doublecheck your code for typos or syntax errors.</p>';
}
}
?>

<div class="">
<div class="" style="margin-top:0px;margin-bottom:15px;">
<div class="" style="width:50%">
<form id="Form1" name="Form1" action="" method="POST">
<label for="fname">First Name*</label><br>
<input type="text" name="fname" id="fname" required autofocus><br><br>

<label for="lname">Last Name*</label><br>
<input type="text" name="lname" id="lname" required><br><br>

<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"><br>
<input type="submit">
</form>
</div>
</div>
</div>

<script src="https://www.google.com/recaptcha/api.js?render=<?php echo RECAPTCHA_SITE_KEY; ?>"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
document.getElementById('g-recaptcha-response').value=token;
});
});
</script>
</body>
</html>

For More  Details  visit Our Website 

SCO 23-24-25, Sector 34A
Chandigarh, IN 160022

(+91) 9988741983

counselor.cbitss@gmail.com

reCAPTCHA V3 Example in PHP

Related Posts :

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

android-training-in-chandigarh " 20000/- to 25000/-

SCO 23-24-25, level 3, sector 34 A CHANDIGARH, Chandigarh, 160022, India

Phone: 9988741983