9
reCAPTCHA v.2.0. Example Form
reCAPTCHA v.2.0. Sample Form. You need to get API key for your site. https://www.google.com/recaptcha/admin#list
//submit.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name=viewport content="width=device-width, initial-scale=1" />
<meta name="description" content="devCodePro" />
<meta name="ROBOTS" content="All" />
<script src="https://www.google.com/recaptcha/api.js"></script>
<style>
body{background-color:#fff;font-family:tahoma,serif;font-size:15px;color:#555;font-weight:900;width:40%;overflow:hidden;margin:50px auto 0}
.info{padding:15px;text-align:center;background:#6C89B5;color:#fff;margin:0 5px}
pre{background:#F7F7F7;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;color:#354165;font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,sans-serif;font-size:15px}
</style>
</head>
<body>
<?php
if(isset($_POST['query'])) {
echo "<pre>".var_dump($_POST)."</pre>";
if(isset($_POST['g-recaptcha-response'])) {
$recaptcha = $_POST['g-recaptcha-response'];
} else {
echo "<div class='info'>Please check the the captcha</div>";
die();
}
if(!$recaptcha) {
echo "<div class='info'>Please check the the captcha</div>";
die();
}
$mySecretKey = "----Enter Secret Key----";
$ip = $_SERVER['REMOTE_ADDR'];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$mySecretKey."&response=".$recaptcha."");
print_r("<pre>".$response."</pre>");
$getResponse = json_decode($response,true);
if(intval($getResponse['success']) !== 1) {
echo "<div class='info'>Error</div>";
} else {
echo "<div class='info'>Thank You</div>";
}
} else {
?>
<form action="submit.php" method="post">
<div class="g-recaptcha" data-sitekey="Enter Site Key"></div>
<div>
<input type="submit" value="Query" name="query" />
</div>
</form>
<?php } ?>
</body>
</html>
rated 9 times
(9)
(0)
comments: 1 / hits: 13448
/ 4 years ago, mon, jan 9, 17, 02:50:09
More From
» PHP
Comments
1
Awesome, the only working solution among hundreds of other not working tutorials. Very easy and implemented in seconds. Thanks :)
[#27] Wednesday, January 1, 2020, 8:53:15

commented 1 year ago
waleedbarakat
Only authorized users can post. Please sign in first, or register a free account