duanhai4046 2018-01-11 06:51 采纳率: 100%
浏览 1844
已采纳

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.

  • 写回答

3条回答 默认 最新

  • doulongti5932 2018-01-11 07:05
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?