Advertisement
MichalCzEJ

Untitled

Mar 1st, 2019
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function login(){
  2. global $db, $username, $errors;
  3.  
  4. // grap form values
  5. $username = e($_POST['username']);
  6. $password = e($_POST['password']);
  7.  
  8. // make sure form is filled properly
  9. if (empty($username)) {
  10. array_push($errors, "Username is required");
  11. }
  12. if (empty($password)) {
  13. array_push($errors, "Password is required");
  14. }
  15. $query = "SELECT * FROM users WHERE username='$username' LIMIT 1";
  16. $results = mysqli_query($db, $query);
  17. $logged_in_user = mysqli_fetch_assoc($results);
  18.  
  19.  
  20. if (password_verify($password, $logged_in_user["password"])){
  21. // check if user is admin or user
  22.  
  23.  
  24. if ($logged_in_user['user_type'] == 'admin') {
  25.  
  26. $_SESSION['user'] = $logged_in_user;
  27. header('location: index.php');
  28. }else{
  29. $_SESSION['user'] = $logged_in_user;
  30. header('location: index.php');
  31. }
  32. } else {
  33. array_push($errors, "Wrong username/password combination");
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement