Codeigniter login system with session to redirect user to page if password correct Codeigniter login system with session to redirect user to page if password correct codeigniter codeigniter

Codeigniter login system with session to redirect user to page if password correct


add if statement with logged_in and a redirect to login form if it is incorrect

public function index()        {             if($this->session->userdata('logged_in'))            {                  $this->load->view('header');            $this->load->view('employee');            $this->load->view('login/footer');           }else{               redirect('user_authentication/user_login_show');            }        }


Best Practice is to add the check in the constructor of your controller in CI.here is the example of mine.

 public function __construct() {    parent::__construct();    if (!$this->session->userdata('user_data')) {        return redirect('login');    }    $this->load->model('customer_model');}

you can add the else statement to redirect to the dashboard or what the resulting page if user is logged in.


Add this line of code to your constructors:

$this->load->library('session');

This will help you.