1index.html
2
3<html>
4 <head>
5 <title>Google recapcha demo - Codeforgeek</title>
6 <script src='https://www.google.com/recaptcha/api.js'></script>
7 </head>
8 <body>
9 <h1>Google reCAPTHA Demo</h1>
10 <form id="comment_form" action="form.php" method="post">
11 <input type="email" placeholder="Type your email" size="40"><br><br>
12 <textarea name="comment" rows="8" cols="39"></textarea><br><br>
13 <input type="submit" name="submit" value="Post comment"><br><br>
14 <div class="g-recaptcha" data-sitekey="=== Your site key ==="></div>
15 </form>
16 </body>
17</html>
18verify.php
19
20<?php
21 $email; $comment; $captcha;
22
23 if(isset($_POST['email']))
24 $email=$_POST['email'];
25 if(isset($_POST['comment']))
26 $comment=$_POST['comment'];
27 if(isset($_POST['g-recaptcha-response']))
28 $captcha=$_POST['g-recaptcha-response'];
29
30 if(!$captcha){
31 echo '<h2>Please check the the captcha form.</h2>';
32 exit;
33 }
34
35 $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=YOUR SECRET KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
36 if($response['success'] == false)
37 {
38 echo '<h2>You are spammer ! Get the @$%K out</h2>';
39 }
40 else
41 {
42 echo '<h2>Thanks for posting comment.</h2>';
43 }
44?>