ini_set无法设置会话变量 - PHP 7.2.0及更高版本

问题描述:

here´s an example with gc_maxlifetime but it worked for none of the session. variables I tried

<?php
session_start();
ini_set('session.gc_maxlifetime', 1500);

this used to work, until PHP 7.2.0 and now throws this warning:

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /in/nOv0L on line 3

enter image description here

https://3v4l.org/nOv0L

I checked the changelog but I can´t find the reason for it.

can anyone tell me what changed, and how I can work around it?


p.s. I know that I could do it like this:

 ini_set('session.gc_maxlifetime', 1500);
 session_start();

but that´s not really the point of my question.

Even if there is no warning, changing the setting after the session has started will not have any effect.

The manual says

Garbage collection may occur during session start

so if you change the value after you start the session it will have no effect. This is also true for most other session parameters.

What you're probably experiencing is an artefact of other changes such as the addition of this message as a warning (all other sources I found like e.g. Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time mention it just as a "message" with no associated level).

Well, make all configuration changes before you start the session:

ini_set('session.gc_maxlifetime', 1500);
session_start();

我也遇到这个问题,但是我不知道怎么解决???