How to change the session timeout in PHP?

Spread the love

Sometimes, we want to change the session timeout in PHP.

In this article, we’ll look at how to change the session timeout in PHP.

How to change the session timeout in PHP?

To change the session timeout in PHP, we can call ini_set to set the 'session.gc_maxlifetime' value.

For instance, we write

ini_set('session.gc_maxlifetime', 3600);

to set the session.gc_maxlifetime session timeout value to 3600 seconds.

And we write

session_set_cookie_params(3600);
session_start();

to set session data to be kept for 1 hour with session_set_cookie_params.

Conclusion

To change the session timeout in PHP, we can call ini_set to set the 'session.gc_maxlifetime' value.

Leave a Reply

Your email address will not be published.