Php 为什么session_unset()不';会话_destroy()后没有任何效果?
通过阅读,我发现Php 为什么session_unset()不';会话_destroy()后没有任何效果?,php,session,unset,Php,Session,Unset,通过阅读,我发现destroy并没有清理变量之类的注释 为什么下面的代码没有清理$\u会话超全局,它应该通过文档来清理 这种行为是否有记录在案 要复制的代码段: #!/usr/bin/php <?php session_start(); $_SESSION['x'] = 1; // If you uncomment this, `session_unset` works as intended. session_destroy(); // It doesn't matter if
destroy
并没有清理变量之类的注释
$\u会话
超全局,它应该通过文档来清理#!/usr/bin/php
<?php
session_start();
$_SESSION['x'] = 1;
// If you uncomment this, `session_unset` works as intended.
session_destroy();
// It doesn't matter if you call unset, it won't have any effect
// as session_destroy was called.
session_unset();
fwrite(STDERR, var_export($_SESSION, true));
// prints: array ('x' => 1), even though session_unset was called
#/usr/bin/php
因为session_destroy()将删除与该用户相关的所有会话。
我认为此行为与默认会话驱动程序的实现有关。(见附件)
当调用session\u destroy
时,PHP触发会话类处理程序的destroy
方法。也许它只销毁数据,而不必触摸$\u SESSION
,当调用SESSION\u unset
时,它会在每个$\u SESSION
项上进行验证,如果项的键被保留,它会删除它,如果不保留,它什么也不做
最后,当您首先调用session\u destroy
时,所有数据都会被销毁,因此session\u unset
在会话[$key]
未持久化时无法执行任何操作
<?php
foreach($_SESSION as $key=>$value)
{
global $data_persisted; //fictive variable containing persisted datas as array
if(isset($data_persisted[$key])
{
unset($_SESSION[$key]);
}
}
看看这个answer@JaiDixit我在发帖前看到了。这不能解释我的问题。