Advertisement
Guest User

Untitled

a guest
Feb 28th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost":
  4. $dBUsername = "";
  5. $dBPassword = "";
  6. $dBName = "admhap_Users";
  7.  
  8. $conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
  9.  
  10. if(!$conn) {
  11. die("Connection failed: ".mysqli_connect_error());
  12. }
  13.  
  14. <?php
  15. require "header.php";
  16. ?>
  17.  
  18. <main>
  19. <div>
  20. <section>
  21. <h1>Aanmelden</h1>
  22. <form action="back-end/signup.be.php" method="post">
  23. <input type="text" name="uid" placeholder="Gebruikersnaam...">
  24. <input type="text" name="mail" placeholder="E-mail...">
  25. <input type="password" name="ww" placeholder="Wachtwoord...">
  26. <input type="password" name="ww-her" placeholder="Herhaal wachtwoord...">
  27. <button type="submit" name="signup-submit">Aanmelden</button>
  28. </form>
  29. </section>
  30. </div>
  31. </main>
  32.  
  33. <?php
  34. require "footer.php";
  35. ?>
  36.  
  37. <?php
  38. if (isset($_POST['signup-submit'])) {
  39.  
  40. require 'dbh.be.php';
  41.  
  42. $username = $_POST['uid'];
  43. $email = $_POST['mail'];
  44. $password = $_POST['ww'];
  45. $passwordRepeat = $_POST['ww-her'];
  46.  
  47.  
  48. if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
  49. header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
  50. exit();
  51. }
  52. else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  53. header("Location: ../signup.php?error=invalidmailuid");
  54. exit();
  55. }
  56. else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  57. header("Location: ../signup.php?error=invalidmail&uid=".$username);
  58. exit();
  59. }
  60. else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  61. header("Location: ../signup.php?error=invaliduid&mail=".$email);
  62. exit();
  63. }
  64. else if ($password !== $passwordRepeat) {
  65. header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
  66. exit();
  67. }
  68. else {
  69.  
  70. $sql = "SELECT gebruikersnaam FROM gebruikers WHERE gebruikersnaam=?";
  71. $stmt = mysqli_stmt_init($conn);
  72. if (!mysqli_stmt_prepare($stmt, $sql)) {
  73. header("Location: ../signup.php?error=sqlerror");
  74. exit();
  75. }
  76. else {
  77. mysqli_stmt_bind_param($stmt, "s", $username);
  78. mysqli_stmt_execute($stmt);
  79. mysqli_stmt_store_result($stmt);
  80. $resultCheck = mysqli_stmt_num_rows($stmt);
  81. if ($resultCheck > 0) {
  82. header("Location: ../signup.php?error=usertaken&mail=".$email);
  83. exit();
  84. }
  85. else {
  86.  
  87. $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
  88. $stmt = mysqli_stmt_init($conn);
  89. if (!mysqli_stmt_prepare($stmt, $sql)) {
  90. header("Location: ../signup.php?error=sqlerror");
  91. exit();
  92. }
  93. else{
  94. $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
  95.  
  96. mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  97. mysqli_stmt_execute($stmt);
  98. header("Location: ../signup.php?signup=succes");
  99. exit();
  100. }
  101.  
  102. }
  103. }
  104.  
  105. }
  106. mysqli_stmt_close($stmt);
  107. mysqli_close($conn);
  108.  
  109. }
  110. else{
  111. header("Location: ../signup.php?");
  112. exit();
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement