Yes, you can change the session cookie timeout in your php.ini file by updating two main directives:
🔧 Step-by-step Instructions
-
Locate your
php.inifile:-
On most systems, it's in
/etc/php/[version]/apache2/php.inior/etc/php.ini. -
Run
php --iniin the terminal to find the correct file if you're unsure.
-
-
Open
php.iniin a text editor:(Replace the path with the actual one from your system if different.)
-
Edit the session timeout settings:
Add or modify the following lines:
-
session.gc_maxlifetime: This is the number of seconds after which data will be seen as 'garbage' and cleaned up by PHP's garbage collection. -
session.cookie_lifetime: This sets how long the cookie should live on the client side (in seconds). If set to0, the cookie expires when the browser closes.
Example:
3600seconds = 1 hour. -
-
Save and close the file.
-
Restart your web server:
-
For Apache:
-
For Nginx with PHP-FPM:
-
Â
Tip for Application-Level Override
If you don't have access to php.ini, you can add this to your script:
Â