Avatar ·

How to set PHP session lifetime to 30 minutes and automatically destroy it?

Hello everyone! I'm a beginner in PHP and I've encountered a problem with session management. I need the user session on my site to automatically expire after 30 minutes of inactivity. I read the documentation but got confused with the settings.\n\nHere's what I tried:\n\n```php\n// At the beginning of each page\nsession_start();\n// Tried to set the lifetime via ini_set\nini_set('session.gc_maxlifetime', 1800);\nini_set('session.cookie_lifetime', 1800);\n```\n\nBut this doesn't work — the session still remains active even after an hour. I check the user's last activity time like this:\n\n```php\nif (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {\n session_destroy();\n session_unset();\n header('Location: login.php');\n exit;\n}\n$_SESSION['LAST_ACTIVITY'] =