Welcome Guest, Not a member yet? Register   Sign In
First post and trouble with sessions
#1

[eluser]thesleepydog[/eluser]
hello,

This is my first post and I just wanted to say that this forum is a wealth of knowledge. I'm fairly experienced with HTML and CSS. I'm pretty good with PHP as well. I'm fairly new to CI and MVC but I like what I've seen so far.

That being said...here is my problem. I'm using SimpleLoginSecure and sessions stored in a database. I'm under the impression that when I use the logout function for SimpleLoginSecure which calls sess_destroy that the row in my database will be deleted. This is not the case. Any help is much appreciated. My code is listed below.


session config
Code:
$config['sess_cookie_name']  = 'ci_session';
$config['sess_expiration']  = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'ci_sessions';
$config['sess_match_ip']  = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

function from controller
Code:
public function logout()
    {
        
        $this->user_model->logout();
        
        //redirect to login screen
        redirect('/user/login', 'refresh');
        
    }

function from model
Code:
public function logout()
    {
        //use simpleloginsecure to destroy session and update database session table
        $this->simpleloginsecure->logout();
        
    }

function from simpleloginsecure
Code:
function logout() {
  $this->CI =& get_instance();
  $this->CI->session->sess_destroy();
  
  
}

and for reference the sess_destroy function
Code:
/**
  * Destroy the current session
  *
  * @access public
  * @return void
  */
function sess_destroy()
{
  // Kill the session DB row
  if ($this->sess_use_database === TRUE AND isset($this->userdata['session_id']))
  {
   $this->CI->db->where('session_id', $this->userdata['session_id']);
   $this->CI->db->delete($this->sess_table_name);
  }

  // Kill the cookie
  setcookie(
     $this->sess_cookie_name,
     addslashes(serialize(array())),
     ($this->now - 31500000),
     $this->cookie_path,
     $this->cookie_domain,
     0
    );
  
  
}
#2

[eluser]CroNiX[/eluser]
No, it doesn't remove it from the database immediately. It does the same thing as regular PHP sessions and mark it for deletion which then goes into garbage collection, which doesn't guarantee it will be removed right then.

You can always set up a cron script to delete any entries where the last_activity is longer than sess_expiration to guarantee they are removed daily. They'll eventually get removed, but that depends on your servers php.ini settings for garbage collection.

You could also extend the session library to have that row deleted when sess_destroy() is called or something.

BTW, I'd change your sess_cookie_name and remove any underscores. IE has problems with cookies with underscores in the name.
#3

[eluser]thesleepydog[/eluser]
It just seems to me that $this->db->delete() should remove it immediately. But I get what you're saying. Thanks for the response.




Theme © iAndrew 2016 - Forum software by © MyBB