S
S
Stardust2020-05-12 13:57:10
MySQL
Stardust, 2020-05-12 13:57:10

How to implement correct authorization with sessions on codeigniter?

Good afternoon, dear, I need help with authorization.
There are 3 tables in the database, Contractor, Client and Manager.
How to make authorization by login, password and role? Thus from different tables? Do not judge strictly, I'm just learning ... I would be grateful for any statement .. 5eba7fc662ee4391448325.jpeg
Model code with the authorization function

public function login_user ($login_cli, $password_cli) // авторизация аккаунта
  {
    //$password_cli=md5(md5(trim($_POST['password_cli']))); // расшифр пароля
    $sql = 'select id_client, login_cli, password_cli, naim_client, address_cli, phone_cli, email_cli, rol_cli from client where login_cli = ? and  password_cli = ? ';
    $query = $this->db->query($sql, array($login_cli, $password_cli));
    return $query->row_array();
    
  }

Код авторизации в контроллере 
// авторизация
  public function signin() {
    
        $this->load->view('head');
        $this->load->view('navbar_guest');
        $data['message'] = '';
        if (!empty($_POST))
        {
            $this->load->model('users_model'); // авторизация
            
            $data['signin'] = $this->users_model->login_user($_POST['login_cli'], $_POST['password_cli']);
            if (!empty($data['signin']))
            {
                $sess = array(
                    'id_client' => $data['signin']['id_client'],
                    'naim_client' => $data['signin']['naim_client']
                );
                $this->session->set_userdata($sess);
                redirect('home');
            }
            else  echo " <br><br><br><br><br>";
            var_dump($_POST['login_cli']);
            var_dump($_POST['password_cli']);
            {
                $data['message'] = 'Вы неверно ввели логин или пароль! <br>';
            }
        }
        $this->load->view('signin', $data);
        $this->load->view('footer');
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question