Guest User

Untitled

a guest
Jan 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. $email = trim($_POST['email']);
  4. $password = $_POST['password'];
  5.  
  6. $error = '';
  7.  
  8. if(empty($email) || empty($password)){
  9. $error = '<p class="error">Invaid email or password.</p>';
  10. }else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
  11. $error = '<p class="error">Invaid email or password.</p>';
  12. }else{
  13. $stmt = $link->prepare("SELECT * FROM users WHERE email = ?");
  14. $stmt->bind_param('s', $email);
  15.  
  16. $stmt->execute();
  17.  
  18. /* fetch value */
  19. $res = $stmt->get_result();
  20.  
  21. if($user = $res->fetch_object()){
  22. if(password_verify($password , $user->password )){
  23. //login is true
  24. $_SESSION['user'] = array(
  25. 'uid' => $user->id,
  26. 'email' => $user->email
  27.  
  28. );
  29.  
  30. $_SESSION['login'] = true;
  31.  
  32. if($user_type == "1"){ //check usertype
  33.  
  34. header("Location:dashboard.php");
  35.  
  36. }else{
  37.  
  38. header("Location:dashboard_usr.php");
  39.  
  40. }
  41.  
  42. }else{
  43. $error = '<p style="color: #ea2b1f">Ooops! Invaid email or password.</p>';
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment