简体   繁体   中英

CodeIgniter How to put multiuser login

Good Day Everyone who has an idea on how I can put a multiuser level login. I want to have a work log view and a staff view.

function index()
    {
  
     $sessionid = $this->session->userdata('sessionid');                     
        if (!empty($sessionid)) {                                              
            redirect('worklog');                           
        } else {
            $this->load->view('login');                                       
        }
    }

This code is for validation of the user.

  function validation()  
      {  
           $this->load->library('form_validation');  
           $this->form_validation->set_rules('username', 'Username', 'required');  
           $this->form_validation->set_rules('password', 'Password', 'required');  
           if($this->form_validation->run())  
           {  
                //true  
                $username = $this->input->post('username');  
                $password = $this->input->post('password');  
                //model function  
                $this->load->model('main_model');  
                if($this->main_model->can_login($username, $password))  
                {  
                     redirect('worklog','refresh'); 
                }  
                else  
                {  
                     $this->session->set_flashdata('error', 'Invalid Username and Password');  
                     redirect('login','refresh'); 
                }  
           }  
           else  
           {  
                //false  
                $this->index();  
           }  
      }  
      function enter(){
        if($this->session->userdata('username') != '')
        {
          $this->session->userdata('username');
        }
        else
        {
          redirect('login','refresh'); 
        }
      }

My main_model

public function can_login($username, $password)  
      {  
           $this->db->select('*');
           $this->db->where('username', $username);  
           $this->db->where('password', $password);  
           $query = $this->db->get('users');  
      

//SELECT * FROM users WHERE username = '$username' AND password = '$password'

 if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row) {
                $data['nameofuser'] = $row['fname'] . " " . $row['lname'];
                $data['sessionid'] = $row['id'];
            }

// SET SESSION FOR THE NAME OF USER AND SESSION ID BASED ON DATABASE USER ID COLUMN

$this->session->set_userdata($data);            
        return true;
        } 
        else 
        {
          return false;
        }
  }

Please integrate ion auth library for creating multiuser login system. Ion auth is a library, that is used to implement groups and permissions inside CodeIgniter project.

This is the GitHub repo. of ion auth: https://github.com/benedmunds/CodeIgniter-Ion-Auth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM