Can anyone please explain to me why this works (In their own words, I have already ready everything that exist about sessions trying to get it to work). I just want to make sure it works because that is how it should work before I move on and accept this logic. Here is the code:
What gets me is if I only set "ini_set('session.gc_maxlifetime', 20);" it will not run the garbage collector after 20 seconds (I am not sure how long before it runs, I have not waited long enough).
But when I set "ini_set('session.gc_divisor', 1);" the session data will be lost after about 40 seconds every time (Why not 20?)
From my understanding of gc_divisor it determines probability that the GC runs (gc_probability/gc_divisor). In my case I set it to '1' so it is 1/1 (100%). But this does not really make since either because default is 100 (1/100 = 1%) but that is saying that GC will only run 1 out of 100 session starts, which is not the case because if I set nothing I loose session data every 1440 seconds (session.gc_maxlifetime default value) consistently.
The whole purpose of doing this is I want to make it so that sessions ALWAYS last until the user closes their browser window. I cant figure this out so I will instead set session.gc_maxlifetime to a REALLY high number. Unless of course there is an easier way to do this!
Code:
<?php
ini_set('session.gc_maxlifetime', 20);
ini_set('session.gc_divisor', 1);
session_start();
if(isset($value))
{
$value++;
}
else
{
session_register('value');
$value = 1;
}
Print "You have been here $value times. <br>";
print '<a href="_test.php">Refresh</a>';
?>
What gets me is if I only set "ini_set('session.gc_maxlifetime', 20);" it will not run the garbage collector after 20 seconds (I am not sure how long before it runs, I have not waited long enough).
But when I set "ini_set('session.gc_divisor', 1);" the session data will be lost after about 40 seconds every time (Why not 20?)
From my understanding of gc_divisor it determines probability that the GC runs (gc_probability/gc_divisor). In my case I set it to '1' so it is 1/1 (100%). But this does not really make since either because default is 100 (1/100 = 1%) but that is saying that GC will only run 1 out of 100 session starts, which is not the case because if I set nothing I loose session data every 1440 seconds (session.gc_maxlifetime default value) consistently.
The whole purpose of doing this is I want to make it so that sessions ALWAYS last until the user closes their browser window. I cant figure this out so I will instead set session.gc_maxlifetime to a REALLY high number. Unless of course there is an easier way to do this!