I like to make it doesn’t change when I reflesh the page within 10 seconds
And
I like to make it changes when I reflesh the page after 10 seconds.
The following is my trials for it.
after I opened xampp/php/php.ini, I changed like the following.
And I modified more like the following
After modifying like the above.
I reflesh several times expecting it changes after 10 seconds.
But it seems not to change.
(Q1) Is it possible to control the session time?
(Q2) If it is possible to control the session time, How can I make the value of session_id() is changing whenever I reflesh it after 10 seconds?
It’s for tests.
If I set it by 86,400, I can check only one time a day.
Actually I like to make it 86400, instead of 1440.
I like to make it always alive for a day(86400).
How can I make it always alive for a day without changing the session_id() value “7f1te8nvobuc8v2m9d4lvrphh5”?
if I make it like the following, the session will be alive for a day?
session.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and potentially cleaned up.
So, yes it might get cleaned up after a day. Meaning the session may last for a day, but it might last longer than a day. It will however not last less than a day.
I have modifiation1 above and modification2 below.
(Q3) Are both modification1 above and modification2 below absolutely last the session at least for a day?
But anyway, the gc_probability and gc_divisor together make up the chance that sessions will be cleaned at the start of any PHP request.
So with the settings session.gc_probability=1 and session.gc_divisor=1000 old sessions will be cleaned 1 every 1000 requests. All other 999 requests sessions are not cleaned, even if they expired.
So indeed if you set both to 1 then sessions will always be cleaned, but that has a penalty of being quite heavy. If you really want to stop a session after a certain time you’re better off using the mechanism storing the session start in the session, as I already showed above. That mechanism also has the advantage it will always work regardless of the gc settings in php.ini.
If I visit the page again after 10 seconds with the code below,
I can check that the session is cleared.
However, as soon as I make a refreshing the browser after the session is cleared.
The previous session is still alive with the same value “7f1te8nvobuc8v2m9d4lvrphh5” although what I want is changing the value of the session_id.
<?php
session_start();
if (!isset($_SESSION['session_start'])) {
$_SESSION['session_start'] = time();
}
if (isset($_SESSION['session_start']) && $_SESSION['session_start'] < time() - 10) {
// session ran for more that 10 seconds - buy bye
session_destroy();
Do you mean there’s a special function for changing the value of the session_id after desinated seconds, i.e. 10 seconds on the my example above, in the manual?
I am afraid I have some weakness in reading the manual as a whole due to non-native speaker of English and …