Welcome Guest, Not a member yet? Register   Sign In
keep_flashdata conflict with sessions
#1

[eluser]Unknown[/eluser]
Hi,

hi, i have a configuration library which for every page checks if the user logged in, if logged in, is cookie set, if not set, is the user active for last (some) minutes.


check_login_session() /config/check_login_session
{
if($this->CI->login->is_logged_in())
{
if($session_life > $inactive)
{
$this->CI->session->set_flashdata('uri', 'user/login');
$this->CI->session->set_flashdata('message', 'your session has expired, please login again.');
redirect('user/logout');
}
}
}

I have a logout controller function user/logut

logout()
{
$uri = $this->session->flashdata('uri');
$message = $this->session->flashdata('message');
$this->login->logout(Wink // Library file
$this->session->keep_flashdata('message');
redirect($uri);
}

a login library handling login session creation & logout sesion destroy. In that,
Logout library function login/logut

logout()
{
$this->CI->session->sess_destroy();
}

1. when the user is inactive the control is given to user/logout function
2. and it takes 2 session messages 1. redirect url 2. message.
3. then it calls the login/logout library which destroys the current session.
4. and redirects to the uri sent via flashdata.

here when i use $this->session->keep_flashdata('message'); in user/logout to keep the redirect url, the session is not getting destroyed and when it goes to next page, check login session function is again triggering as the user is not logged out which resulting an infinite loop.

when i remove keep_flashdata message in the logout function of user controller. everything is working fine.
#2

[eluser]must[/eluser]
hi,
by writing
Code:
$this->login->logout(;) // Library file
$this->session->keep_flashdata(‘message’);
first
Code:
$this->login->logout(;)
should be (you should have a syntax mistake showing up if you wrote this in your logout function)
Code:
$this->login->logout();

seconde you're trying to keep a flashdata after destroying the session (wich should destroy flashdata as well) and a new session won't be created until the user goes to another page (by redirect).
the only way to do this that i can come up with is:
Code:
check_login_session()  /config/check_login_session
{
  if($this->CI->login->is_logged_in())
  {
    if($session_life > $inactive)              
    {
      $this->CI->session->set_flashdata(‘message’, ‘your session has expired, please login again.’);
      $this->CI->session->set_flashdata(‘sess_expired’, 'TRUE');

      redirect(‘user/login’);
    }
  }
}

and in you're user controller / login method add somehing like
Code:
if($this->session->flasdata('sess_expired'))
{
    $message = $this->session->flashdata(‘message’);
    $this->login->logout(); // or $this->CI->session->sess_destroy();
    echo $message;
}
bottom line you can't use the flashdata for this. I hope this helped you.




Theme © iAndrew 2016 - Forum software by © MyBB