1

How to call a function just before session gets auto destroyed after timeout in CodeIgniter 4?

I am capturing user logout (ip_address, id_user, id_app) in database, its working fine when user get logout manually (By calling logout method) but I am not able to capture it when user's session gets auto destroyed after timeout.

Please help me to resolve this problem, I am using Codeigniter 4.1.9

I have try extending the Session library:

<?php
namespace App\Libraries;

use CodeIgniter\Session\Handlers\FileHandler;
use App\Libraries\Sac_Lib;          

class MY_Session extends FileHandler
{
    public function gc($max_lifetime)
    {
        $sacLib = new \App\Libraries\Sac_Lib(); 
        $sacLib->writelogapl_ver3('logout',session()->get('id_app'),session()->get('id_user'),$_SERVER['REMOTE_ADDR']);

        parent::gc($max_lifetime);
    }
}

But it not working, because I didn't get record in my database when user's session gets auto destroyed after timeout.

Diaulhak
  • 11
  • 2

1 Answers1

0

You can call function in codeigniter 4, when session get expired. Following example has a method that will be executed when session gets expired and it will execute the defined method

  • you mean I can't do it before the session ends but if after the session ends I can? can you give an example? – Diaulhak May 19 '23 at 03:01
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 19 '23 at 11:36