Home · Latest · Trends  /  PHP
7

reCAPTCHA v.2.0. Example Form

rated 7 times [  7] [ 0]  / comments: 0 / hits: 4851  / 3 years ago, mon, jan 9, 2017, 02:50:09
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>
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Snippets
reCaptcha in smarty template file
3 years ago, mon, dec 5, 2016
PHP stopforumspam integration example ans class
3 years ago, mon, jan 16, 2017
esoTalk forum script / esoTalk-BBCode plugin with color tag [plugin.php] [resources/bbcode.js]
3 years ago, sat, jan 21, 2017
Smarty section start loop: First result, second result, first and second result
3 years ago, fri, feb 10, 2017
PHP replace bad words function / form
3 years ago, fri, feb 10, 2017
Get a domain name IP address with PHP
3 years ago, tue, feb 28, 2017
Get YouTube Video ID and clean URL with PHP
3 years ago, sun, mar 5, 2017
HTML Purifier posting arrays example
3 years ago, thu, mar 16, 2017
Thunderbird userchrome.css example C://Users/<USER>/AppData/Roaming/Thunderbird/Profiles/<PROFILE>/chrome/userChrome.css
3 years ago, sun, apr 16, 2017
Sponsor
Posted
jimmy

jimmy

Member since Dec 15, 2016
Total Code Snippets: 16
Total Comments: 2
Location: n/a
Following
User not following anyone yet.