首页 > 解决方案 > 为什么我的 $_SESSION 会在文件之间丢失多维数组数据?

问题描述

我确信我的问题确实来自于不了解一个非常基本的机制,但我已经花了几个小时,但我仍然无法解决问题。

我做了两个测试文件:test1.php:

//as you can see I did some research, yet it looks that my session save path is fine, so this is not the case
if (is_writable(session_save_path()))
    echo 'ok <br />';

$_SESSION['test'] = '!!!single!!!'; //this saves and stays in the $_SESSION
$_SESSION[1]['test'] = '???multi???'; //this dissapears - but why and how to prevent this?

print_r($_SESSION);
?>

结果:

ok 数组 ( [test] => !!!single!!! [1] => Array ( [test] => ???multi??? ) )

完全符合预期。

测试2.php:

if (is_writable(session_save_path()))
    echo 'ok <br />'; //just to be sure

print_r($_SESSION); //why, oh why?
?>

结果:

好的数组( [test] => !!!single!!! )

而我的“[1] => Array ([test] => ???multi??? )” 不存在...但是为什么呢?超全局 $_SESSION 设置如上,没有任何改变......

我的服务器确实将 register_globals 设置为关闭 - 好吧,可能是这种情况吗?即使-我不想就那样打开它。无论如何,这似乎是错误的事情。

非常感谢提前,最好的问候!

标签: phparrayssessionsession-variables

解决方案


推荐阅读