Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. <?php
  2. require "server.php";
  3.  
  4. $username = $password = $confirm_password = "";
  5. $username_err = $password_err = $confirm_password_err = "";
  6. $itime = time();
  7. $cash = 5000;
  8. $bankcash = 5000;
  9. $rank = 1;
  10. $rankstring = "Powder Monkey";
  11. $exp = 0;
  12. $killskill = 0;
  13. $jointime = time();
  14. $crimetime = "";
  15.  
  16. if($_SERVER["REQUEST_METHOD"] == "POST"){
  17. if(empty(trim($_POST["username"]))){
  18. $username_err = "Please enter a username.";
  19. } else{
  20. // Prepare a select statement
  21. $sql = "SELECT id FROM users WHERE username = ?";
  22.  
  23. if($stmt = mysqli_prepare($link, $sql)){
  24. // Bind variables to the prepared statement as parameters
  25. mysqli_stmt_bind_param($stmt, "s", $param_username);
  26.  
  27. // Set parameters
  28. $param_username = trim($_POST["username"]);
  29.  
  30. // Attempt to execute the prepared statement
  31. if(mysqli_stmt_execute($stmt)){
  32. /* store result */
  33. mysqli_stmt_store_result($stmt);
  34.  
  35. if(mysqli_stmt_num_rows($stmt) == 1){
  36. $username_err = "This username is already taken.";
  37. } else{
  38. $username = trim($_POST["username"]);
  39. }
  40. } else{
  41. echo "Oops! Something went wrong. Please try again later.";
  42. }
  43. }
  44.  
  45. // Close statement
  46. mysqli_stmt_close($stmt);
  47. }
  48.  
  49. // Validate password
  50. if(empty(trim($_POST["password"]))){
  51. $password_err = "Please enter a password.";
  52. } elseif(strlen(trim($_POST["password"])) < 6){
  53. $password_err = "Password must have atleast 6 characters.";
  54. } else{
  55. $password = trim($_POST["password"]);
  56. }
  57.  
  58. // Validate confirm password
  59. if(empty(trim($_POST["confirm_password"]))){
  60. $confirm_password_err = "Please confirm password.";
  61. } else{
  62. $confirm_password = trim($_POST["confirm_password"]);
  63. if(empty($password_err) && ($password != $confirm_password)){
  64. $confirm_password_err = "Password did not match.";
  65. }
  66. }
  67.  
  68. if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
  69. $sql = "INSERT INTO users (username, password, cash, bankcash, rank, rankstring, exp, killskill, jointime, itime, crimetime)
  70. VALUES (?, ?, $cash, $bankcash, $rank, $rankstring, $exp, $killskill, $jointime, $itime, $crimetime)";
  71.  
  72. if($stmt = mysqli_prepare($link, $sql)){
  73. // Bind variables to the prepared statement as parameters
  74. mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
  75.  
  76. // Set parameters
  77. $param_cash = $cash;
  78. $param_bankcash = $bankcash;
  79. $param_rank = $rank;
  80. $param_rankstring = $rankstring;
  81. $param_exp = $exp;
  82. $param_killskill = $killskill;
  83. $param_jointime = $jointime;
  84. $param_itime = $itime;
  85. $param_crimetime = $crimetime;
  86. $param_username = $username;
  87. $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
  88.  
  89. // Attempt to execute the prepared statement
  90. if(mysqli_stmt_execute($stmt)){
  91.  
  92. // Redirect to login page
  93. header("location: login.php");
  94. } else{
  95. echo "Something went wrong. Please try again later.";;
  96. }
  97. }
  98.  
  99. // Close statement
  100. mysqli_stmt_close($stmt);
  101. }
  102.  
  103. // Close connection
  104. mysqli_close($link);
  105. }
  106. ?>
  107.  
  108.  
  109. <!DOCTYPE html>
  110. <html lang="en">
  111. <head>
  112. <meta charset="UTF-8">
  113. <title>Sign Up</title>
  114. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  115. <style type="text/css">
  116. body{ font: 14px sans-serif; }
  117. .wrapper{ width: 350px; padding: 20px; }
  118. </style>
  119. </head>
  120. <body>
  121. <div class="wrapper">
  122. <h2>Sign Up</h2>
  123. <p>Please fill this form to create an account.</p>
  124. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  125. <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
  126. <label>Username</label>
  127. <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
  128. <span class="help-block"><?php echo $username_err; ?></span>
  129. </div>
  130. <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
  131. <label>Password</label>
  132. <input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
  133. <span class="help-block"><?php echo $password_err; ?></span>
  134. </div>
  135. <div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
  136. <label>Confirm Password</label>
  137. <input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
  138. <span class="help-block"><?php echo $confirm_password_err; ?></span>
  139. </div>
  140. <div class="form-group">
  141. <input type="submit" class="btn btn-primary" value="Submit">
  142. <input type="reset" class="btn btn-default" value="Reset">
  143. </div>
  144. <p>Already have an account? <a href="login.php">Login here</a>.</p>
  145. </form>
  146. </div>
  147. </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement