Advertisement
wunude0011

Signup page php

Apr 10th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['signup-submit'])) {
  3.  
  4. require 'dbh.inc.php';
  5.  
  6. $username = $_POST['uid'];
  7. $email = $_POST['mail'];
  8. $password = $_POST['pwd'];
  9. $passwordRepeat = $_POST['pwd-repeat'];
  10.  
  11.  
  12. if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
  13.  header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
  14. exit();
  15. }
  16. else if (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  17. header("Location: ../signup.php?error=invaliduid");
  18. exit();
  19. }
  20. else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  21.  header("Location: ../signup.php?error=invalidmail&uid=".$username);
  22. exit();
  23. }
  24. else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
  25.  header("Location: ../signup.php?error=invaliduid&mail=".$email);
  26. exit();
  27. }
  28.  else if ($password !== $passwordRepeat) {
  29.  header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
  30.  exit();
  31. }
  32. else {
  33.  
  34. $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
  35. $stmt = mysqli_stmt_init($conn);
  36. if (!mysqli_stmt_prepare($stmt, $sql)) {
  37. header("Location: ../signup.php?error=sqlerror");
  38. exit();
  39. }
  40.  else {
  41.  mysqli_stmt_bind_param($stmt, "s", $username);
  42.  mysqli_stmt_execute($stmt);
  43.  mysqli_stmt_store_result($stmt);
  44. $resultCheck = mysqli_stmt_num_rows($stmt);
  45. if ($resultCheck > 0) {
  46.  header("Location: ../signup.php?error=usertaken&mail=".$email);
  47. exit();
  48.  }
  49. else {
  50.  
  51. $sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?) ";
  52. $stmt = mysqli_stmt_init($conn);
  53. if (!mysqli_stmt_prepare($stmt, $sql)) {
  54. header("Location: ../signup.php?error=sqlerror");
  55. exit();
  56. }
  57. else {
  58.  $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
  59.  
  60.  mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
  61.  mysqli_stmt_execute($stmt);
  62.  header("Location: ../signup.php?signup=success");
  63. exit();
  64.    
  65. }
  66.  
  67. }
  68.  
  69. }
  70.  
  71. }
  72. }
  73.  
  74. else {
  75.     header("Location: ../signup.php");
  76.     exit();
  77. }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement