Guest User

Untitled

a guest
Jan 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. session_start();
  2. if(!$_SESSION['sess_role'] == 'role1') {
  3. header('location:../../index.php');
  4. }
  5.  
  6. $msg = "";
  7. if(isset($_POST['submitBtnLogin'])) {
  8. $username = trim($_POST['username']);
  9. $password = trim($_POST['password']);
  10. if($username != "" && $password != "") {
  11. try {
  12. $query = "select * from `users` where `username`=:username and `password`=:password";
  13. $stmt = $db->prepare($query);
  14. $stmt->bindParam('username', $username, PDO::PARAM_STR);
  15. $stmt->bindValue('password', $password, PDO::PARAM_STR);
  16. $stmt->execute();
  17. $count = $stmt->rowCount();
  18. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  19. if($count == 1 && !empty($row)) {
  20.  
  21. $_SESSION['sess_user_id'] = $row['id'];
  22. $_SESSION['sess_username'] = $row['username'];
  23. $_SESSION['sess_role'] = $row['role'];
  24. }
  25.  
  26. if($row['role'] == "role1") {
  27. header('location:modules/role1/index.php');
  28. } else if($row['role'] == "role2") {
  29. header('location:modules/role2/index.php');
  30. } else if($row['role'] == "role3") {
  31. header('location:modules/role3/index.php');
  32. } else if($row['role'] == "role4") {
  33. header('location:modules/role4/index.php');
  34.  
  35. } else {
  36. $msg = "Invalid login information.";
  37. }
  38. } catch (PDOException $e) {
  39. echo "Error : ".$e->getMessage();
  40. }
  41. } else {
  42. $msg = "Both fields are required.";
  43. }
  44. }
  45.  
  46. echo($_SESSION['sess_role']);
Add Comment
Please, Sign In to add comment