0

I am sorry if I am asking a question that is already asked. After reading all the previous questions I still cannot find the solution of my issue. All I want is to remove the user session in ci_sessions table after the user has logged out as it is removing in the browser. Up to now I still cannot do it. As a result the ci_sessions table is getting bigger and bigger each time a user logs in.

Please help me know how to prevent the terrible increasement of the ci_sessions table by removing the user sessions each time he logs out or close his browser.

Version used : 3.1.5

1- config.php

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
 $config['sess_regenerate_destroy'] = FALSE;

2- controller

 //login function
  public function login()
   {
  $data = array(
  'admin_id'=>$id,
   'admin_name' =>$name,
   'admin_perfil'=>$perfil,
    'is_logged_in' => true
    );
    $this->session->set_userdata($data);
   }

  // log out

   public function admin_logout()
     {
     $array_items = array(
            'admin_name', 
            'admin_password',
            'admin_perfil',
            'admin_id',
            'is_logged_in',
            );

       $this->session->sess_destroy();

    $this->session->unset_userdata($array_items);
       }
Diasline
  • 625
  • 3
  • 32
  • 2
    read this as to why that isn't necessary https://stackoverflow.com/questions/15360819/does-codeigniters-ci-sessions-need-occasional-emptying – Alex Oct 22 '18 at 15:51
  • Possible duplicate of [Does CodeIgniter's ci\_sessions need occasional emptying?](https://stackoverflow.com/questions/15360819/does-codeigniters-ci-sessions-need-occasional-emptying) – Javier Larroulet Oct 22 '18 at 16:52
  • Thank you for the link. According the link I understand that I must set ['sess_regenerate_destroy'] to TRUE. – Diasline Oct 22 '18 at 18:10
  • Do i need to decrease as well the value of ['sess_expiration'] and ['sess_time_to_update'] ? – Diasline Oct 22 '18 at 18:11
  • @Diasline, `sess_regenerate_destory` has nothing to do with cleanup (garbage collection). Please [read this](https://stackoverflow.com/questions/7828975/php-garbage-collection-clarification) and then [read this](https://www.dev-metal.com/how-the-php-session-garbage-collector-really-works/) Then check that in php.ini that `session.gc_probability` is greater than 0. – DFriend Oct 23 '18 at 00:39

0 Answers0