Advertisement
Guest User

signup.php

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