· 7 years ago · Jan 03, 2019, 06:58 AM
1<?php
2 if (isset($_POST['submit'])) {
3 $username = $_POST[username];
4 $secretkey = "6LcbEoYUAAAAABWCUd2TfWnLj6Ad77m1A5XFy7vm";
5 $response = $_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
23<html>
24 <head>
25 <title>PHP Recaptcha Tutorial</title>
26 </head>
27 <body>
28 <form action="index.php" method="post">
29 <input type="text" name="username" placeholder="What is your name?">
30 <input type="submit" name="submit" value="Save">
31 <div class="g-recaptcha" data-sitekey="6LcbEoYUAAAAANyf3lHmY4xypqE96au_0AyDf1DH"></div>
32 </form>
33 <script src='https://www.google.com/recaptcha/api.js'></script>
34
35
36
37
38 </body>
39
40
41
42
43
44
45
46
47</html>