乐闻世界logo
搜索文章和话题

CodeIgniter extend user's session expiration time

1个答案

1

In CodeIgniter, session configuration is set in the application's configuration file. Specifically, in the application/config/config.php file. To extend the user session expiration time, you need to adjust the $config['sess_expiration'] parameter in this configuration file.

By default, $config['sess_expiration'] is set to 7200 seconds, equivalent to 2 hours. If you wish for the session to last longer, such as 4 hours, set this value to 14400 seconds (4 hours).

For example, the code modification is as follows:

php
$config['sess_expiration'] = 14400;

Additionally, there is another configuration related to session expiration time: $config['sess_time_to_update'], which determines how often the session ID is updated. By default, this value is 300 seconds (5 minutes). You can adjust this time according to your needs to accommodate user activity patterns.

One important point to note is that if your website uses the 'Remember Me' feature, you may need to set a long-lived Cookie during user login, which is typically achieved by setting additional Cookies during login rather than solely relying on session expiration time.

In summary, by adjusting both $config['sess_expiration'] and $config['sess_time_to_update'], you can flexibly extend the user session time on your CodeIgniter website as needed.

2024年8月12日 14:21 回复

你的答案