猿问

使用 codeigniter 在 php&mysqli 中进行多级登录

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

请帮助我,谢谢你之前

数据库映像

代码图像

    <?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');

        }

    }

}


繁星淼淼
浏览 147回答 1
1回答

largeQ

尝试为您的会话添加级别并稍后在仪表板页面上阅读:&nbsp; &nbsp; &nbsp; &nbsp; $session = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'id'=> $d->admin_id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'nama'=> $d->admin_nama,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'status' => 'login',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'level' => $d->level&nbsp; &nbsp; &nbsp; &nbsp; );在仪表板页面上if($this->session->userdata["level"] === "superadmin"){&nbsp; &nbsp;// Code if level = superadmin}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答