· 7 years ago · Jan 05, 2019, 12:14 AM
1<?php
2
3 include_once('db.php');
4
5 $nick = $_POST['nick'];
6 $sql = "INSERT INTO SpongeAntiBot (Nick) VALUES ('$nick')";
7
8 $nickcheck = "SELECT * FROM SpongeAntiBot WHERE nick = '$nick'";
9
10 $query = "SELECT Nick FROM SpongeAntiBot WHERE Nick = '$nick'";
11
12 $result = mysqli_query($conn, $query);
13
14
15 $username = $_POST['nick'];
16 $secretKey = "6LfjjX8UAAAAAA7jdlsu9uJuHFIR7D-Dlivh7WjJ";
17 $responseKey = $_POST['g-recaptcha-response'];
18 $userIP = $_SERVER['REMOTE_ADDR'];
19
20
21 $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
22 $response = file_get_contents($url);
23
24 $response = json_decode($response);
25
26 if ($response->success) {
27
28 if (mysqli_num_rows($result) > 0) {
29
30 echo '
31 <script>
32 $(document).ready(function() {
33 Swal({
34 position: "center",
35 type: "error",
36 title: "Usuário já registado!",
37 showConfirmButton: false,
38 timer: 1600
39 });
40 });
41 </script>
42 ';
43 }
44 else {
45
46 if (mysqli_query($conn, $sql)) {
47
48 echo '
49 <script>
50 $(document).ready(function() {
51 Swal({
52 position: "center",
53 type: "success",
54 title: "Usuário registado!",
55 showConfirmButton: false,
56 timer: 1600
57 });
58 });
59 </script>
60 ';
61 }
62 else {
63 echo "Um error foi encontrado.";
64 }
65 }
66
67 }
68 else {
69
70 echo '
71 <script>
72 $(document).ready(function() {
73 Swal({
74 position: "center",
75 type: "error",
76 title: "Preencha o captcha!",
77 showConfirmButton: false,
78 timer: 1600
79 });
80 });
81 </script>
82 ';
83
84 }
85
86?>