I am newbie in Codeigniter PHP. I have developed a simple user management system in this on user login i have set database session. I also destroy them on logout. My Caching is also turned off. Even though when i click on back button on browser i can see my dashboard,if i click on any link then it redirects me to login,but it shows me the dashboard at first which is a bug. Please help me solve it.
Model:
public function login ()
{
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->hash($this->input->post('password')),
), TRUE);
if (count($user)) {
// Log in user
$data = array(
'name' => $user->name,
'email' => $user->email,
'id' => $user->id,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
}
}
public function logout ()
{
$this->session->sess_destroy();
$this->session->unset_userdata('logged_in','id','name','email');
}
public function loggedin ()
{
return (bool) $this->session->userdata('loggedin');
}
Controller:
public function login ()
{
// Redirect a user if he's already logged in
$dashboard = 'user/dashboard';
$this->userlogin_m->loggedin() == FALSE || redirect($dashboard);
// Set form
$rules = $this->userlogin_m->rules;
$this->form_validation->set_rules($rules);
// Process form
if ($this->form_validation->run() == TRUE) {
// We can login and redirect
if ($this->userlogin_m->login() == TRUE) {
redirect($dashboard);
}
else {
$this->session->set_flashdata('error', 'That email/password combination does not exist');
redirect('user/secure/login', 'refresh');
}
}
// Load view
$this->data['subview'] = 'user/secure/login';
$this->load->view('user/_layout_modal', $this->data);
}
public function logout ()
{
$this->userlogin_m->logout();
redirect('user/secure/login');
}