Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. // if everything is valid then set valid_form to true
  2. $valid_form = $valid_email && $valid_password;
  3.  
  4. if ($valid_form) {
  5. // Create connection
  6. include 'config.php';
  7.  
  8. // check if email exists in database
  9. $stmt = $db->prepare("SELECT Email_Address, Password, Role, First_Name FROM users WHERE Email_Address=?");
  10.  
  11. $stmt->bind_param('s', $email);
  12.  
  13. // running insert statement
  14. if ($stmt->execute() === TRUE) {
  15. echo "Email checked successfully";
  16. } else {
  17. echo "Error: " . $db->error;
  18. }
  19.  
  20. // bind result variables
  21. $stmt->bind_result($stored_email, $stored_password, $stored_role, $stored_first_name);
  22.  
  23. // fetch value
  24. $stmt->fetch();
  25.  
  26. // close statement
  27. $stmt->close();
  28.  
  29. // close the connection
  30. $db->close();
  31.  
  32. // if email address does not exist, redirect back to login page with an error message
  33. if ($stored_email == NULL) {
  34. $_SESSION['error_email'] = "That email address does not exist";
  35. $_SESSION['alertMessage'] = $msg_fail;
  36. header("Location: login.php");
  37. die();
  38. }
  39.  
  40. // check the password in the database against the user submitted password
  41. $correct_password = password_verify($password, $stored_password);
  42.  
  43. // if matching, send user to welcome page
  44. if ($correct_password) {
  45. /* get info about the logged in user to use elsewhere */
  46. $_SESSION['first_name'] = $stored_first_name;
  47. $_SESSION['role'] = $stored_role;
  48. $_SESSION['email_address'] = $stored_email;
  49. $_SESSION['logged_in'] = true;
  50. if ($stored_role == "User") {
  51. header("Location: dashboard-user.php");
  52. die();
  53. }
  54. header("Location: dashboard-agent.php");
  55. die();
  56. } else {
  57. $_SESSION['error_password'] = "Your password is incorrect";
  58. $_SESSION['alertMessage'] = $msg_fail;
  59. header("Location: login.php");
  60. die();
  61. }
  62.  
  63. } else {
  64. $_SESSION['alertMessage'] = $msg_fail;
  65. header("Location: login.php");
  66. die();
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement