session_regenerate_id 没有创建新的会话 ID [英] session_regenerate_id is not creating a new session id

查看:32
本文介绍了session_regenerate_id 没有创建新的会话 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,用于完成当前会话并开始一个新会话.我使用了一段代码,它在我的开发计算机上运行良好.但是,当我将其发布到生产服务器时,会话 ID 一直保持不变.

I have a script which is meant to finish the current session and start a new one. There is a segment of code I use and it works fine on my development computer. However, when I posted it to the production server, the session id is constantly remaining the same.

以下是我重新启动会话的代码:

The following is my code for restarting the session:

session_start();

$_SESSION = array();
$_POST = array();
$_GET = array();

if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), 
              '', 
              time() - 42000,
              $params["path"], 
              $params["domain"],
              $params["secure"], 
              $params["httponly"]
    );
}
session_destroy();
session_write_close();
session_start();    

session_regenerate_id(true);

在最后一行,没有生成新的会话 ID.

On the last line, a new session id is not generated.

为什么两台运行 PHP 的服务器会有所不同?我能做些什么来纠正它?

Why would this be different between two servers running PHP? And what can I do to correct it?

推荐答案

经过一些试验,我解决了这个问题.

After some experimenting I solved the problem.

如果任何文本已写入响应,则 session_regenerate_id(true) 行不会重新生成新的会话 ID.我已经有一系列 echo 语句发出用于调试目的的文本,在我删除它们之后,新的会话 ID 被创建.

The session_regenerate_id(true) line does not regenerate a new session id if any text has been written into the response. I already had a series of echo statements issuing text for debugging purposes and after I removed them new session ids were created.

这篇关于session_regenerate_id 没有创建新的会话 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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