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;
        }       
    }

}


?>

Recommended Answers

All 3 Replies

need some help to to that

What have you tried?

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'];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.