Skip to content
PHP Logo

How can the ini_set() function be used to modify session settings in PHP?

To modify session settings in PHP using the ini_set() function, you can set the session configuration options directly in your PHP script. This can be useful when you need to change session settings on a per-script basis without modifying the php.ini file.

php
// Set session cookie lifetime to 1 hour
ini_set('session.cookie_lifetime', 3600);

// Set session garbage collection probability to 1%
ini_set('session.gc_probability', 1);

// Start the session
session_start();

// Your PHP code here