PHP 7.2警告:“当会话处于活动状态时,不能更改会话名称”。 [英] PHP 7.2 Warning: "Cannot change session name when session is active"

查看:481
本文介绍了PHP 7.2警告:“当会话处于活动状态时,不能更改会话名称”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们服务器上的PHP已从7.0升级到7.2。如果完成了新部署,我将收到以下警告(导致错误)。原因可能是,旧会话在部署后会失效。

Since PHP on our server was upgraded to 7.2 from 7.0. I am getting the following warning (which leads to error) if a new deployment is done. The reason is probably, that old sessions get invalid after deployment.


警告:session_name():在会话时无法更改会话名称在第137行上的
有效
/var/www/html/model/login/lib/Session.class.php

Warning: session_name(): Cannot change session name when session is active in /var/www/html/model/login/lib/Session.class.php on line 137

警告:session_set_cookie_params ():当会话在第138行的
/var/www/html/model/login/lib/Session.class.php中处于活动状态时,无法更改会话cookie
参数

Warning: session_set_cookie_params(): Cannot change session cookie parameters when session is active in /var/www/html/model/login/lib/Session.class.php on line 138

警告:无法修改标头信息-
已发送的标头(输出从
开始/ var / www / html / model / login / lib /在第142行的
/var/www/html/model/login/lib/Session.class.php中的Session.class.php:137)

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/model/login/lib/Session.class.php:137) in /var/www/html/model/login/lib/Session.class.php on line 142

在会话上下文和特定上下文中,PHP 7.2似乎变得更加严格。服务器似乎识别出无效的会话,并尝试销毁那些无效的会话。这是Session类的一部分:

It seems like PHP 7.2 got more strict in the context of session sin a certain context. The server seems to recognize the invalid sessions and tries to destroy those. This is part of the Session class:

/**
 * Secure instant destruction of session. Must be called after session_start !
 */
public static function destroyAbsolute() {

    self::checkInit(); // unimportant

    session_name(self::$name); // this is line 137
    session_set_cookie_params(0, COOKIEPATH, null, self::$force_ssl_cookie, true);

    if(session_id()) {
        if (isset($_COOKIE[session_name()])) {
            setcookie(session_name(), "", time() - 42000, COOKIEPATH);
        }
        unset($_COOKIE[session_name()]);
        session_destroy();
    }
}

关于会话的PHP发生了什么变化?

What has changed in PHP regarding sessions?

如果另一个会话处于活动状态,为什么不允许设置会话名称(根据具有session_name的文档,我可以更改会话并启动多个会话)?

Why is it not allowed to set a session name if another session is active (according to the docs with session_name I could change sessions and start multiple sessions)?

我该如何适当地销毁正在运行的会话?

And how may I destroy the running session appropriately?

我还需要做进一步的研究在GitHub上找到了以下讨论( https://github.com/Icinga/icingaweb2/issues/3185 )。 他们确认此错误是PHP 7.2引入的。不幸的是,也没有答案:-/

Doing further research I also have found the following discussion on GitHub (https://github.com/Icinga/icingaweb2/issues/3185). They confirm that this error was introduced with PHP 7.2. Unfortunatly there is also no answer :-/

推荐答案

我在php.net上做了一个错误报告,他们解释说这是不是错误。 是的,现在在PHP 7.2中会生成警告。但这从未按预期进行,只是默默地失败了

I have done a bug report at php.net and they explained that this is not a bug. Yes in PHP 7.2 a warning is generated now. However this never worked as intended, it just failed silently.

要创建多个会话,需要使用 session_id()。看看这个相关的问题: PHP如何创建多个会话?

For creating multiple sessions it is required to use session_id(). Have a look at this related question: PHP How can I create multiple sessions?

session_name()以及 session_set_cookie_params()总是无意义。

对于原始答案,请在此处查看: https://bugs.php.net/bug.php?id=75650&thanks=2

For the original answer have a look here: https://bugs.php.net/bug.php?id=75650&thanks=2

这篇关于PHP 7.2警告:“当会话处于活动状态时,不能更改会话名称”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆