Advertisement
KitSaels

users.php

Apr 4th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php declare(strict_types=1);
  2.  
  3. if (!isset($_POST['login-submit'])) {
  4.     header("Location: ../index.php");
  5.     exit();
  6. }
  7.  
  8. require 'dbh.inc.php';
  9.  
  10. $mailuid = $_POST['mailuid'] ?? null;
  11. $password = $_POST['pwd'] ?? null;
  12.  
  13. if (empty($mailuid) ||  empty($password)) {
  14.     header("Location: ../index.php?error=emptyfields");
  15.     exit();
  16. }
  17. $sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
  18. $stmt = mysqli_stmt_init($conn);
  19. if (!mysqli_stmt_prepare($stmt, $sql)) {
  20.     header("Location: ../index.php?error=sqlerror");
  21.     exit();
  22. }
  23. mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
  24. mysqli_stmt_execute($stmt);
  25. $result = mysqli_stmt_get_result($stmt);
  26. if (!$row = mysqli_fetch_assoc($result)) {
  27.     header("Location: ../index.php?error=nouser");
  28.     exit();
  29. }
  30. $pwdCheck = password_verify($password, $row['pwdUsers']);
  31. if ($pwdCheck == false) {
  32.     header("Location: ../index.php?error=wrongpwd");
  33.     exit();
  34. }
  35. session_start();
  36. $_SESSION['userId'] = $row['idUsers'];
  37. $_SESSION['userUid'] = $row['uidUsers'];
  38.  
  39. header("Location: ../index.php?login=success");
  40. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement