Guest User

Untitled

a guest
Feb 11th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public function login($uname,$upass)
  2. {
  3. try
  4. {
  5. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userName=:name_id");
  6. $stmt->execute(array(":name_id"=>$uname));
  7. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  8.  
  9. if($stmt->rowCount() == 1)
  10. {
  11. if($userRow['userStatus']=="Y")
  12. {
  13. if($userRow['userPass']==md5($upass))
  14. {
  15. $_SESSION['userSession'] = $userRow['userID'];
  16. return true;
  17. }
  18. else
  19. {
  20. header("Location: index.php?error");
  21. exit;
  22. }
  23. }
  24. else
  25. {
  26. header("Location: index.php?inactive");
  27. exit;
  28. }
  29. }
  30. else
  31. {
  32. header("Location: index.php?error");
  33. exit;
  34. }
  35. }
  36. catch(PDOException $ex)
  37. {
  38. echo $ex->getMessage();
  39. }
  40. }
  41.  
  42. public function is_logged_in()
  43. {
  44. if(isset($_SESSION['userSession']))
  45. {
  46. return true;
  47. }
  48. }
  49.  
  50. public function redirect($url)
  51. {
  52. header("Location: $url");
  53. }
  54.  
  55. public function logout()
  56. {
  57. session_destroy();
  58. $_SESSION['userSession'] = false;
  59. }
  60.  
  61. // LOGIN //
  62. $user_login = new USER();
  63.  
  64. if($user_login->is_logged_in()!="")
  65. {
  66. $user_login->redirect('home.php');
  67. }
  68.  
  69. if(isset($_POST['btn-login']))
  70. {
  71. $email = trim($_POST['txtemail']);
  72. $upass = trim($_POST['txtupass']);
  73.  
  74. if($user_login->login($email,$upass))
  75. {
  76. $user_login->redirect('home.php');
  77. }
  78. }
Add Comment
Please, Sign In to add comment