duanhai4046 2018-01-11 14:51 采纳率: 100%
浏览 1828
已采纳

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 15: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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口