Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录PHP后如何获取用户ID会话?_Php_Database_Function_Session - Fatal编程技术网

登录PHP后如何获取用户ID会话?

登录PHP后如何获取用户ID会话?,php,database,function,session,Php,Database,Function,Session,最后一页是模型中的“database.php”: case 'login':{ if(isset($_POST['login'])) { $username = $_POST['username']; $password = md5($_POST['password']); if($db->login($username, $password)){ $_S

最后一页是模型中的“database.php”:

case 'login':{
        if(isset($_POST['login']))
        {
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            if($db->login($username, $password)){
                $_SESSION['user_name'] = $username;

                //$_SESSION['user_id'] = $userID;

                if($_SESSION['user_type'] == 1){
                    header('location: index.php?controller=admin&action=adminhomepage');
                }else{
                    header('location: index.php?controller=view&action=homepage');
                }   
            } else{
                header('location: index.php?controller=user&action=login');
            }
        }
        require_once('View/login.php');
        break;
    }

我不知道如何获得会话的用户ID以及用户类型登录成功后的网站。我只获得用户名的会话。救救我

我希望你不打算把这个放到网上;这是完全不安全的使用。是的,我只是有一个PHP的基本知识,我正在做最后的项目。我只是想知道如何获得用户ID会话
case 'login':{
        if(isset($_POST['login']))
        {
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            if($db->login($username, $password)){
                $_SESSION['user_name'] = $username;

                //$_SESSION['user_id'] = $userID;

                if($_SESSION['user_type'] == 1){
                    header('location: index.php?controller=admin&action=adminhomepage');
                }else{
                    header('location: index.php?controller=view&action=homepage');
                }   
            } else{
                header('location: index.php?controller=user&action=login');
            }
        }
        require_once('View/login.php');
        break;
    }
public function login($username, $password){
        $sql = "SELECT * FROM user WHERE UserName='$username' AND Password='$password'";
        $this->execute($sql);
        return $this->getAllData(array($username,$password));
    }