There are several scripts

1.php

<?php ini_set('session.gc_maxlifetime', 10); ini_set('session.cookie_lifetime', 10); session_set_cookie_params(10)); session_start(); $_SESSION['studentid']=$_POST['studentid']; ?> //html <form> на 2.php 

2.php

 <?php session_start(); if (!isset($_SESSION['studentid'])) { echo 'no id'; } var_dump($_SESSION); ?> 

If I go to 1.php and wait for> 10 seconds and confirm the form referring to 2.php, the condition with $ _SESSION ['studentid'] does not work there, but in var_dump ($ _ SESSION); it will be seen that $ _SESSION ['studentid'] is still alive and the session is still in memory. Although I obviously entered 10 seconds before the start of the session using all the familiar methods. Why it happens? I need that if the user is sitting for more than 10 seconds on 1. php, then in 2. php there was no longer his $ _SESSION ['studentid'] there.

  • one
    session.gc_maxlifetime is not a very simple parameter, this is the time after which the session file is allowed to delete, the deletion is started depending on the parameters session.gc_probability and session.gc_divisor i - zb '

1 answer 1

maybe you do differently?

in the 1.php file, create a session variable with a timestamp, and in the 2.php file, check the difference between the current time and the timestamp in the session - and here you are already doing your logic)