PHP 会话设置为变量并取消设置


PHP Session set into variable and unset it.

只是一个简短的问题。

我正在尝试将会话存储到变量中,然后在第二行中尝试取消设置会话。在我的变量变为空之后。

//Assuming session Hello has a value already
$hello_world = $this->Session->read('Hello');
$this->Session->delete('Hello');
print_r($hello_world); //empty here where it shouldn't ...

您正在删除会话变量

$this->Session->delete('Hello');

因此,名称为 Hello 的会话变量将从会话中删除。查看此链接

尝试回显变量,因为它不是一个数组。 如果不起作用,那么您必须发布整个视图。