PHP increase session time

When you use PHP sessions for your applications, the sessions have a specific period of time that they remain active for when idle. The session time is restored when you are active though.

Applications timing out too quick and asking you to login again because the PHP session has expired can be frustrating.

Increase the PHP session lifetime to stay logged in longer.

The PHP directive is session.gc_maxlifetime and there are several ways of setting it depending on your server setup:

Via PHP Code

You can try to use ini_set('session.gc_maxlifetime', 3600); in your application before session_start(); is called.

Via cPanel/WHM/etc

Your hosting control panel may provide you with a PHP configuration editor where you can set the PHP directive to increase the PHP session time accordingly.

Ask Your Hosting Provider

If you don’t manage with this, best will be to ask your hosting provider or server administrator. They will know what to do.

I would like to extend the session timeout in phpI know that it is possible to do so by modifying the php.ini file.But I don’t have access to it.So is it possible to do it only with php code?

Source: How to change the session timeout in PHP? – Stack Overflow


1 Comment

  1. Hello,

    This is very helpful.

    Thank you!

Leave a Reply to Mushtak Cancel reply

Your email address will not be published.


© 2021 Contrid

Theme by Anders NorénUp ↑

Pin It on Pinterest

%d bloggers like this: