I am performing a session start in which it is mandatory that the Keep Me Connected field is present, and that the user presses the checkbox and sends the data, his session is kept started for a period of 3 days, and otherwise it only lasts a day. I am doing it in the following way:
<input name="sesion" type="checkbox" id="signed-in"/>
<label for="signed-in">Mantenerme Conectado</label>
if(!empty($_POST['sesion'])){
ini_set('session.cookie_lifetime', time() + (60*60*72));
} else {
ini_set('session.cookie_lifetime', time() + (60*60*24));
}
The problem that is throwing me is this:
Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in line 17
Now I don't know if it's because before that I have the session_start declared, I really don't know. Or if there is a better way to keep me logged in I would really appreciate your help. Thank you
You are making a set of a configuration directive. What you would need is to make a session cookie set. To do this you can use session_set_cookie_params() where the first argument is the time to live.
Before continuing, two notes:
time() + (60*60*24)
will give you a time to live until 2066 ( at the time of writing the answer ).Try something like this:
As a side note , session_set_cookie_params() does not set the time to live if there is already a session created. Therefore, if a session has been started before the Keep me logged in is selected and sent , the time to live change will not take effect. You would have to either not log in until you submit this form, or delete the current session and re-create a new one with the new session lifetime data.
EDIT
If you have an external file to start the session, you just have to modify the approach a bit.
The login does the default set of the time to live ( ttl )...
... and if the new session is authorized, the new ttl is set .