Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. <?php
  2.  
  3. include("inc/init.php");
  4.  
  5. session_start();
  6. if(isset($_SESSION['id'])) {
  7. header("Location: members.php");
  8. }
  9.  
  10. $errors = array();
  11.  
  12. $firstname = $lastname = $username = $email = "";
  13.  
  14.  
  15. if(isset($_POST['register'])) {
  16. $firstname = $_POST['firstname'];
  17. $lastname = $_POST['lastname'];
  18. $username = $_POST['username'];
  19. $email = $_POST['email'];
  20. $password = $_POST['password'];
  21.  
  22. if(empty($firstname)) {
  23. $pos = count($errors);
  24. $errors[$pos] = "Your firstname can't be empty";
  25. } else if(strlen($firstname) > 255) {
  26. $pos = count($errors);
  27. $errors[$pos] = "Your firstname can't contain more than 255 characters";
  28. }
  29.  
  30. if(empty($lastname)) {
  31. $pos = count($lastname);
  32. $errors[$pos] = "Your lastname can't be empty";
  33. } else if(strlen($lastname) > 255) {
  34. $pos = count($errors);
  35. $errors[$pos] = "Your lastname can't contain more than 255 characters";
  36. }
  37.  
  38. if(!empty($username)) {
  39. if(strlen($username) < 4) {
  40. $pos = count($errors);
  41. $errors[$pos] = "Your username must contain atleast 4 characters";
  42. } else if(strlen($username) > 14) {
  43. $pos = count($errors);
  44. $errors[$pos] = "Your username can't contain more than 14 characters";
  45. }
  46. } else {
  47. $pos = count($errors);
  48. $errors[$pos] = "Your username can't be empty";
  49. }
  50.  
  51. if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  52. $pos = count($errors);
  53. $errors[$pos] = "You entered an invalid email";
  54. }
  55.  
  56. if(!empty($password)) {
  57. if(strlen($password) < 8) {
  58. $pos = count($errors);
  59. $errors[$pos] = "Your password must contain atleast 8 characters";
  60. } else if(strlen($password) > 22) {
  61. $pos = count($errors);
  62. $errors[$pos] = "Your password can't contain more than 22 characters";
  63. }
  64. }
  65.  
  66. if($getUsername = $conn->prepare("SELECT username FROM users WHERE username=?")) {
  67. $getUsername->bind_param("s", $username);
  68. $getUsername->execute();
  69. $getUsername->store_result();
  70. $usernameRows = $getUsername->num_rows;
  71.  
  72. if($usernameRows > 0) {
  73. $errors[] = "Username is already in use";
  74. }
  75. } else {
  76. $errors[] = "Could not fetch usernames. Please try again later";
  77. }
  78.  
  79.  
  80. if($getEmail = $conn->prepare("SELECT username FROM users WHERE email=?")) {
  81. $getEmail->bind_param("s", $email);
  82. $getEmail->execute();
  83. $getEmail->store_result();
  84. $emailRows = $getEmail->num_rows;
  85.  
  86. if($emailRows > 0) {
  87. $errors[] = "Email is already in use";
  88. }
  89. } else {
  90. $errors[] = "Could not fetch emails. Please try again later";
  91. }
  92.  
  93.  
  94. if(count($errors) <= 0) {
  95. // Success
  96. $stmt = $conn->prepare("INSERT INTO users (firstname, lastname, username, email, password) VALUES (?, ?, ?, ?, ?)");
  97. $stmt->bind_param("sssss", $firstname, $lastname, $username, $email, $hpassword);
  98.  
  99. $firstname = $_POST['firstname'];
  100. $lastname = $_POST['lastname'];
  101. $username = $_POST['username'];
  102. $email = $_POST['email'];
  103. $pwd = $_POST['password'];
  104. $hpassword = password_hash($pwd, PASSWORD_DEFAULT);
  105.  
  106. $stmt->execute();
  107. }
  108. }
  109.  
  110. ?>
  111.  
  112. <!DOCTYPE html>
  113. <html lang="en">
  114. <head>
  115. <meta charset="UTF-8">
  116. <title>Register</title>
  117. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  118. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  119. <link rel="stylesheet" href="../css/main.css">
  120. </head>
  121. <body>
  122. <?php include("inc/header.php"); ?>
  123. <div class="registerpage">
  124. <div class="container">
  125. <div class="contents-left">
  126. <img src="images/logo.png" alt="" id="logo">
  127. <p class="desc">
  128. WELCOME TO CHRILLE332.XYZ! JOIN NOW TO MAKE NEW FRIENDS, CREATE GROUPS, ADD PHOTOS, AND MUCH MORE.
  129. </p>
  130. <div class="button">
  131. <a href="/login"><input type="submit" value="Login" class="btn btn-default"></a>
  132. </div>
  133. </div>
  134. <div class="contents-right">
  135. <div class="form-inner">
  136. <div id="register-form">
  137. <div class="panel panel-default">
  138. <div class="panel-heading"><span><strong>Login</strong></span></div>
  139. <div class="panel-body">
  140. It's free and will forever be
  141. <form action="" method="post">
  142. <!--- Break | Firstname -->
  143. <div class="form-group">
  144. <input type="text" name="firstname" placeholder="Firstname" class="form-control" value="<?php echo $firstname; ?>">
  145. </div>
  146.  
  147. <!--- Break | Lastname -->
  148. <div class="form-group">
  149. <input type="text" name="lastname" placeholder="Lastname" class="form-control" value="<?php echo $lastname; ?>">
  150. </div>
  151.  
  152. <!--- Break | Username -->
  153. <div class="form-group">
  154. <input type="text" name="username" placeholder="Username" class="form-control" value="<?php echo $username; ?>">
  155. </div>
  156.  
  157. <!--- Break | Email -->
  158. <div class="form-group">
  159. <input type="email" name="email" placeholder="Email" class="form-control" value="<?php echo $email; ?>">
  160. </div>
  161.  
  162. <!--- Break | Password -->
  163. <div class="form-group">
  164. <input type="password" name="password" placeholder="Password" class="form-control" value="">
  165. </div>
  166. <input type="submit" name="register" value="Register" class="btn btn-default">
  167. <?php if(count($errors) > 0): ?>
  168. <div class="alert alert-danger">
  169. <?php
  170. for($i = 0; $i < count($errors); $i++) {
  171. echo "<li>".$errors[$i]."</li>";
  172. }
  173. ?>
  174. </div>
  175. <?php endif; ?>
  176.  
  177. </form>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185.  
  186. </body>
  187. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement