-1

i want to add another function for level of access in this code. admin=3 artist=2 client=1. like that. but need some help to to that :( thankyou in advance (:

<?php
include('password.php');
class User extends Password{

    private $_db;

    function __construct($db){
        parent::__construct();

        $this->_db = $db;
    }

    private function get_user_hash($username){  

        try {
            $stmt = $this->_db->prepare('SELECT password FROM members WHERE username = :username AND active="Yes" ');
            $stmt->execute(array('username' => $username));

            $row = $stmt->fetch();
            return $row['password'];

        } catch(PDOException $e) {
            echo '<p class="bg-danger">'.$e->getMessage().'</p>';
        }
    }

    public function login($username,$password){

        $hashed = $this->get_user_hash($username);

        if($this->password_verify($password,$hashed) == 1){

            $_SESSION['loggedin'] = true;
            return true;
        }   
    }

    public function logout(){
        session_destroy();
    }

    public function is_logged_in(){
        if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
            return true;
        }       
    }

}


?>
4
Contributors
3
Replies
38
Views
3 Years
Discussion Span
Last Post by fireburner29
0

Hi,
First add in members table a field, lets named this field "role", and make it of type int.
In this field put the level acces of the user.
After that your SELECT can be changed like this:

SELECT password, role FROM members WHERE username = :username AND active="Yes"

Finally you can put the role extracted in session

$_SESSION['role'] = $row['role'];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.