Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- session_start();
- if(!$_SESSION['sess_role'] == 'role1') {
- header('location:../../index.php');
- }
- $msg = "";
- if(isset($_POST['submitBtnLogin'])) {
- $username = trim($_POST['username']);
- $password = trim($_POST['password']);
- if($username != "" && $password != "") {
- try {
- $query = "select * from `users` where `username`=:username and `password`=:password";
- $stmt = $db->prepare($query);
- $stmt->bindParam('username', $username, PDO::PARAM_STR);
- $stmt->bindValue('password', $password, PDO::PARAM_STR);
- $stmt->execute();
- $count = $stmt->rowCount();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if($count == 1 && !empty($row)) {
- $_SESSION['sess_user_id'] = $row['id'];
- $_SESSION['sess_username'] = $row['username'];
- $_SESSION['sess_role'] = $row['role'];
- }
- if($row['role'] == "role1") {
- header('location:modules/role1/index.php');
- } else if($row['role'] == "role2") {
- header('location:modules/role2/index.php');
- } else if($row['role'] == "role3") {
- header('location:modules/role3/index.php');
- } else if($row['role'] == "role4") {
- header('location:modules/role4/index.php');
- } else {
- $msg = "Invalid login information.";
- }
- } catch (PDOException $e) {
- echo "Error : ".$e->getMessage();
- }
- } else {
- $msg = "Both fields are required.";
- }
- }
- echo($_SESSION['sess_role']);
Add Comment
Please, Sign In to add comment