php - 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;
}
}
Answer
Solution:
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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function format() on string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.