Welcome Guest, Not a member yet? Register   Sign In
Set session expiration time based on user role in CodeIgniter 4
#4

(04-11-2025, 06:18 AM)Beewez Wrote: Hi everyone,

I'm working with CodeIgniter 4 and I need to configure the session expiration time dynamically based on the user role at login.

I understand that, by default, CodeIgniter loads session settings from app/Config/Session.php, where the 'expiration' value is defined. However, this configuration is static and applied globally.

What I want to achieve is something like this:
  • If the user has the admin role, their session should last longer.
  • If the user has a standard role, the session should expire sooner.

I’m wondering if there’s a recommended way to override the session expiration time at runtime based on the user role. Is it possible to change the expiration after login, or would I need to implement a custom logic to handle expiration manually?

Any advice or example would be greatly appreciated. fr legends mod koenigsegg
Thanks in advance!

Yes, you can override session expiration dynamically after login by updating session()->set() with custom timeout logic based on user role—just ensure session regeneration to apply the new lifetime correctly.
Reply


Messages In This Thread
RE: Set session expiration time based on user role in CodeIgniter 4 - by marlon01 - 05-05-2025, 11:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB