· 9 years ago · Jan 24, 2017, 10:54 PM
1<html>
2 <head>
3 <title>Google recapcha demo - Codeforgeek</title>
4 <script src='https://www.google.com/recaptcha/api.js'></script>
5 </head>
6 <body>
7 <h1>Google reCAPTHA Demo</h1>
8 <form id="comment_form" action="form.php" method="post">
9 <input type="submit" name="submit" value="Submit"><br><br>
10 <div class="g-recaptcha" data-sitekey="6LcpDhMUAAAAAEzyk81J_rJevvJGKDGyc0m2iznf"></div>
11 </form>
12 </body>
13</html>
14
15<?php
16 $captcha;
17 if(isset($_POST['g-recaptcha-response'])){
18 $captcha=$_POST['g-recaptcha-response'];
19 }
20 if(!$captcha){
21 echo '<h2>Please check the the captcha form.</h2>';
22 exit;
23 }
24 $secretKey = "6LcpDhMUAAAAAOs8YlIcmbSCusGIifxgcVXeYcI2";
25 $ip = $_SERVER['REMOTE_ADDR'];
26 $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
27 $responseKeys = json_decode($response,true);
28 if(intval($responseKeys["success"]) !== 1) {
29 echo '<h2>You are spammer ! Get the @$%K out</h2>';
30 } else {
31 echo '<h2>Thanks for posting comment.</h2>';
32 }
33?>