CodeIgniter Forums
CI 4.3.5 - Session Expiration Not Working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: CI 4.3.5 - Session Expiration Not Working (/showthread.php?tid=89142)

Pages: 1 2


CI 4.3.5 - Session Expiration Not Working - shashi - 01-15-2024

Hi,

I am using CI 4.3.5
I have set

Code:
    /**
    * --------------------------------------------------------------------------
    * Session Expiration
    * --------------------------------------------------------------------------
    *
    * The number of SECONDS you want the session to last.
    * Setting to 0 (zero) means expire when the browser is closed.
    */
    public int $expiration = 43200;  // 12 hour - i need after 12 hour , session should be destroy for all users , so they can re login again.

But its not working  , can any one tell me what will be issue ?

Thanks


RE: CI 4.3.5 - Session Expiration Not Working - InsiteFX - 01-16-2024

Try using the CodeIgniter 4 Time Constants.
43260 = 1 minute after 12 hours, try that

PHP Code:
/*
 |--------------------------------------------------------------------------
 | Timing Constants
 |--------------------------------------------------------------------------
 |
 | Provide simple ways to work with the myriad of PHP functions that
 | require information to be in seconds.
 */
defined('SECOND') || define('SECOND'1);
defined('MINUTE') || define('MINUTE'60);
defined('HOUR')  || define('HOUR'3600);
defined('DAY')    || define('DAY'86400);
defined('WEEK')  || define('WEEK'604800);
defined('MONTH')  || define('MONTH'2_592_000);
defined('YEAR')  || define('YEAR'31_536_000);
defined('DECADE') || define('DECADE'315_360_000); 



RE: CI 4.3.5 - Session Expiration Not Working - shashi - 01-16-2024

Thanks for reply ,

you mean to say

Code:
public int $expiration = 43200; // for this : 60*60*12 = 43200

instead

public int $expiration = 43260; // but 43260 = 12 hour , how ?  can you please explain ?



RE: CI 4.3.5 - Session Expiration Not Working - InsiteFX - 01-16-2024

That should set the expire time that you want if it's not working then you may have a problem
some place else in the code or php.ini file.

Let me look at the session class and see what it is doing.

The expireation should be done on the session cookie to destroy the session if I remember right.

Note:

If expiration is set to 0, the session.gc_maxlifetime setting set by PHP in session management
will be used as-is (often the default value of 1440).

This needs to be changed in php.ini or via ini_set() as needed.


RE: CI 4.3.5 - Session Expiration Not Working - shashi - 01-16-2024

In my code/php.ini , i dont think any issue  because as per this link : https://codeigniter.com/user_guide/libraries/sessions.html


Quote:expiration 7200 (2 hours)  Time in seconds (integer)

Which work , means after every 2 hours , my logged in users are logout ( their session is destroy ) , but if i put

Quote:43260 = 12 hour  , then its not happening


Quote:If expiration is set to 0, the session.gc_maxlifetime setting set by PHP in session management
will be used as-is (often the default value of 1440).

This needs to be changed in php.ini or via ini_set() as needed.

I am not setting expiration = 0 , i need 43260 = 12 hour  and if we do expiration = 0 , then we need to do changes in php.ini
which is used when

Quote:Setting to 0 (zero) means expire when the browser is closed.

Let me know what can be done ?

or its a bug ?


RE: CI 4.3.5 - Session Expiration Not Working - InsiteFX - 01-16-2024

If you think it's a bug the leave an issue on it in the CodeIniter GitHub for the Developers.


RE: CI 4.3.5 - Session Expiration Not Working - shashi - 01-16-2024

I think so.
Do u or any one have any other solution for it ?
Can you inform CI developers ?
Thank


RE: CI 4.3.5 - Session Expiration Not Working - InsiteFX - 01-16-2024

I found this tonight, this is how to manually set a time out for sessions.
How to Destroy Session After Some Time in PHP ?

So this should be worked into your Auth System like Sheild etc;

I'll take some time later and see what I can come up with for Shield.


RE: CI 4.3.5 - Session Expiration Not Working - shashi - 01-16-2024

I was too thinking something like that , but again that is something we need to build by self and its not feature of CI4.
i was just testing with

Quote:expiration 7200 (2 hours)  Time in seconds (integer)

and found this is also not working , i am sure their is some issue with this version , because early in 4.1.1 it was working fine with 2 hours atleast.

if possible you please inform your team.
Thanks


RE: CI 4.3.5 - Session Expiration Not Working - kenjis - 01-16-2024

I don't understand what is your exact issue? "does not work" explains nothing.
It is better to show what you want and what was happened.

7200 means the lifetime of the session cookie. You can see the value in your browser's developer tool.
If the time has passed (in the browser's clock), the browser deletes the cookie, so the user must re-login.
But if the session data in your server is deleted, the user must re-login when the session cookie still exists.