· 7 years ago · Jan 03, 2019, 07:34 AM
1<?php
2 if (isset($_POST['submit'])) {
3 $username = $_POST['username'];
4 $secretkey = "6LcbEoYUAAAAABWCUd2TfWnLj6Ad77m1A5XFy7vm";
5 $responsekey = $_POST['g-recaptcha-response'];
6 $userIP = $_SERVER['REMOTE_ADDR'];
7
8 $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretkey&response=$responsekey&remoteip=$userIP";
9 $response = file_get_contents($url);
10 $response = json_decode($response);
11 if ($response->success)
12 echo "Verification success. Your name is: $username";
13 else
14 echo "verification failed.";
15
16 }
17
18?>
19
20
21
22<html>
23 <head>
24 <title>PHP Recaptcha Tutorial</title>
25 </head>
26 <body>
27 <form action="index.php" method="post">
28 <input type="text" name="username" placeholder="What is your name?">
29 <input type="submit" name="submit" value="Save">
30 <div class="g-recaptcha" data-sitekey="6LcbEoYUAAAAANyf3lHmY4xypqE96au_0AyDf1DH"></div>
31 </form>
32 <script src='https://www.google.com/recaptcha/api.js'></script>
33
34
35
36
37 </body>
38
39
40
41
42
43
44
45
46</html>