简体   繁体   English

session_regenerate_id正在执行…是吗?

[英]session_regenerate_id executing… double?

I have a strange issue that drives me mad... I was writing my own MVC framework and I was working on session management with mysql, when I noticed that the session_regenerate_id function sometimes was generating new sessions from nowhere... After many hours trying guess what the hell could be wrong, i ended up to bypass all my code and run a white page with this simple php script: 我遇到一个奇怪的问题,这使我发疯……我正在编写自己的MVC框架,并且正在使用mysql进行会话管理,当时我注意到session_regenerate_id函数有时会从无处产生新的会话... 经过数小时的尝试猜猜到底是怎么了,我最终跳过了所有代码,并使用此简单的php脚本运行了一个白页:

<?php
if(!isset($_SESSION)){
session_start();
$_SESSION['user']='kikko68';
$_SESSION['name']='cristian';
$_SESSION['mail']='cri89@kij.com';
}
$old=session_id();
session_regenerate_id(true);
$new=session_id();
echo"OLD = ".$old."<br>NEW = ".$new;
?>

I've tested this script on a web server and this is the result: 我已经在Web服务器上测试了此脚本结果如下:

---------------load page---------------------
OLD = ffa4e90763d61a2f733364fddb86bbf4
NEW = 7293a7268c77406075c78a38bc148c34
---------------refresh-----------------------
OLD = 7293a7268c77406075c78a38bc148c34
NEW = d21e6da87635fb2934b286679850c830
---------------refresh-----------------------
OLD = d21e6da87635fb2934b286679850c830
NEW = 9686e91f66565358bceaa4bac8d8a563

And as you can see at every refresh the NEW id becomes the OLD one. 如您所见,每次刷新时,新ID都会变成旧ID。

On my local installation instead (XAMPP) , things seems to have any sense... 在我的本地安装(XAMPP)上 ,事情似乎有任何意义...

---------------load page---------------------
OLD = c1vgleb55j0tpeu21mr3l1rip5
NEW = dn2hfst79nuqtcegi91qikrv34
---------------refresh-----------------------
OLD = th1tk5dmaovdlrdka4frf07is0
NEW = s7a990magimfccc0qtnl66rfp0
---------------refresh-----------------------
OLD = hkpadq4pjtbtcmap3m3322al21
NEW = q17lh3asev8rkv3ld1f4mu2tk0

Someone can explain me the reason why this is happening? 有人可以向我解释为什么会这样吗? Thanks. 谢谢。

The server results make sense to me, and the XAMPP results do not. 服务器结果对我来说很有意义,而XAMPP结果却没有。 It would appear that in the XAMPP environment, the old session is never being recognized at all. 在XAMPP环境中,似乎似乎根本无法识别旧会话。 So session_start() creates a brand new one with a new ID (that's ID change #1) and then your session_regenerate_id() call creates a further new one (that's ID change #2). 因此,session_start()创建一个具有新ID的全新ID(即ID更改#1),然后您的session_regenerate_id()调用创建另一个新ID(即ID更改#2)。

To test, capture the session ID immediately after session_start(). 要进行测试,请在session_start()之后立即捕获会话ID。 The question should become, not "Why are two IDs being generated in my script?" 问题应该变成,不是“为什么我的脚本中生成了两个ID?” but "Why is my script not finding and loading a valid session on session_start()?" 但是“为什么我的脚本无法在session_start()上找到并加载有效的会话?”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM