我有3个用户具有不同的访问页面,我尝试创建无限制访问权限的登录表单标准。现在我很困惑,我必须在新代码中多次登录。
(我将php&mysqli数据库与codeigniter框架一起使用)

请帮我,
在此之前

database image

code image

    <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct(){
        parent::__construct();
        $this->load->model('m_rental');
    }

    public function index(){
        $this->load->view('login');
    }

    function login(){
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $this->form_validation->set_rules('username','Username','trim|required');
        $this->form_validation->set_rules('password','Password','trim|required');
        if($this->form_validation->run() != false){
            $where = array(
                'admin_username' => $username,
                'admin_password' => $password,      
            );
            $data = $this->m_rental->edit_data($where,'admin');
            $d = $this->m_rental->edit_data($where,'admin')->row();
            $cek = $data->num_rows();
            if($cek > 0){
                $session = array(
                    'id'=> $d->admin_id,
                    'nama'=> $d->admin_nama,
                    'status' => 'login'
                );
                $this->session->set_userdata($session);
                redirect(base_url().'admin');
            }else{
                redirect(base_url().'welcome?pesan=gagal');         
            }
        }else{
            $this->load->view('login');
        }
    }
}

最佳答案

尝试将级别添加到您的会话中,稍后在仪表板页面上阅读:

        $session = array(
            'id'=> $d->admin_id,
            'nama'=> $d->admin_nama,
            'status' => 'login',
            'level' => $d->level
        );


并在仪表板页面上

if($this->session->userdata["level"] === "superadmin")
{
   // Code if level = superadmin
}

08-04 17:20