· 7 years ago · Jun 12, 2018, 02:12 PM
1<?php
2if(isset($_POST['g-recaptcha-response'])) {
3
4 $secretKey = 'secrethereloooooooool';
5 $response = $_POST['g-recaptcha-response'];
6 $remoteIp = $_SERVER['REMOTE_ADDR'];
7
8
9 $reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp");
10 $result = json_decode($reCaptchaValidationUrl, TRUE);
11
12 print_r($result);
13
14 if($result['success'] == 1) {
15
16 $userMessage = '<div>Success: you\'ve made it :)</div>';
17
18 } else {
19
20 $userMessage = '<div>Fail: please try again :(</div>';
21
22 }
23
24}
25?>
26
27<?php
28
29ob_start();
30
31if(file_exists("install.php") == "1"){
32 header('Location: install.php');
33 exit();
34}
35
36include 'inc/database.php';
37
38$result = mysqli_query($con, "SELECT * FROM `settings` LIMIT 1") or die(mysqli_error($con));
39while($row = mysqli_fetch_assoc($result)){
40 $website = $row['website'];
41 $favicon = $row['favicon'];
42}
43
44if (!isset($_SESSION)) {
45 session_start();
46}
47
48if (isset($_SESSION['username'])) {
49 header('Location: index.php');
50 exit();
51}
52
53if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['confirmpassword']) && isset($_POST['email'])){
54
55 $username = mysqli_real_escape_string($con, $_POST['username']);
56 $password = mysqli_real_escape_string($con, md5($_POST['password']));
57 $confirmpassword = mysqli_real_escape_string($con, md5($_POST['confirmpassword']));
58 $email = mysqli_real_escape_string($con, $_POST['email']);
59
60 if($password != $confirmpassword){
61 die("The confirmation password was not equal to the password.");
62 }
63
64 if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
65 die("The email entered was not correct.");
66 }
67
68 $result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username'") or die(mysqli_error($con));
69 if(mysqli_num_rows($result) > 0){
70 die("This username already exists.");
71 }
72
73 $result = mysqli_query($con, "SELECT * FROM `users` WHERE `email` = '$email'") or die(mysqli_error($con));
74 if(mysqli_num_rows($result) > 0){
75 die("This email already exists.");
76 }
77
78 $ip = mysqli_real_escape_string($con, $_SERVER['REMOTE_ADDR']);
79 $date = date('Y-m-d');
80
81 mysqli_query($con, "INSERT INTO `users` (`username`, `password`, `email`, `date`, `ip`) VALUES ('$username', '$password', '$email', '$date', '$ip')") or die(mysqli_error($con));
82
83 header("Location: login.php?action=registered");
84
85}
86
87?>
88
89<!DOCTYPE html>
90<html lang="en">
91<head>
92 <meta charset="utf-8">
93 <meta name="viewport" content="width=device-width, initial-scale=1.0">
94 <meta name="description" content="">
95 <meta name="author" content="24/7">
96 <meta name="keyword" content="">
97 <link rel="shortcut icon" href="<?php echo $favicon;?>">
98
99 <title><?php echo $website;?> - Registration</title>
100 <script src='https://www.google.com/recaptcha/api.js'></script>
101
102 <!-- Bootstrap core CSS -->
103 <link href="css/bootstrap.min.css" rel="stylesheet">
104 <link href="css/bootstrap-reset.css" rel="stylesheet">
105 <!-- Custom styles for this template -->
106 <link href="css/style.css" rel="stylesheet">
107 <link href="css/style-responsive.css" rel="stylesheet" />
108 <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
109 <!--[if lt IE 9]>
110 <script src="js/html5shiv.js"></script>
111 <script src="js/respond.min.js"></script>
112 <![endif]-->
113
114</head>
115
116 <body class="login-body">
117
118 <div class="container">
119
120 <form class="form-signin" action="register.php" method="POST">
121 <h2 class="form-signin-heading"><?php echo $website;?></h2>
122 <div class="login-wrap">
123 <input type="text" id="username" name="username" class="form-control" placeholder="Username" autofocus>
124 <input type="password" id="password" name="password" class="form-control" placeholder="Password">
125 <input type="password" id="confirmpassword" name="confirmpassword" class="form-control" placeholder="Confirm Password">
126 <input type="text" id="email" name="email" class="form-control" placeholder="Email">
127 <div class="g-recaptcha" data-sitekey="6LdLyl0UAAAAAPAm_0Xi17sc3-Noa3Jnw4tLca43"></div>
128 <button class="btn btn-lg btn-login btn-block" type="submit">Register</button>
129 </form>
130
131 <div class="registration">
132 Already have an account? 
133 <a class="" href="login.php">
134 Sign In
135 </a>
136 </div>
137
138 </div>
139
140 </div>
141
142
143
144 <!-- js placed at the end of the document so the pages load faster -->
145 <script src="js/jquery.js"></script>
146 <script src="js/bootstrap.min.js"></script>
147
148 </body>
149</html>