我有三个不同访问页面的用户,我尝试创建无限制访问的登录表单standart。现在我很困惑我必须把新代码放在哪里多次登录。(我使用带有代码点火器框架的php&mysqli数据库(
请帮帮我,前厚度u
数据库图像
代码图像
<?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
}