I want to check login in every controller of my project. if there is no session data i want to redirect to login page and after login i want to come back to same controller.
Thank you.
I want to check login in every controller of my project. if there is no session data i want to redirect to login page and after login i want to come back to same controller.
Thank you.
Have a look at IonAuth which is an authentication library for CodeIgniter. If installed, you can simply write something along the lines of:
class Test extends CI_Controller
{
public function login()
{
$this->load->helper('url');
$this->load->library('ion_auth');
$identity = $this->input->post('email');
$password = $this->input->post('password');
if ($this->ion_auth->login($identity, $password, true)) {
redirect('user/dashboard');
}
redirect('user/login');
}
}