如何返回会话变量并在下次刷新渲染后立即清除它?
我有一个功能,可以显示当前管理登录信息,还可以显示会话变量中包含的反馈消息。
我进行了设置,以便会话变量在显示后立即设置为空。然而,在实现中,我让显示变量的函数像这样显示它:
function loginInfo()
{
$code .= 'You are logged in as bob.';
$code .= 'msg:'.$_SESSION['msg'];
$_SESSION['msg'] = null;
return $code;
}
function breadCrumbs($section = '')
{
$html .= $this->loginInfo();
$html .= '<h1><a href="/admin">Dashboard</a> > '.$section.'</h1>';
return $html;
}
function dashboard()
{
$html .= $this->breadCrumbs('');
$html .= '<ul>';
$html .= etc..
}
-----------
$_SESSION['msg'] = 'message here';
header(Redirect "/admin");
exit();
然后在新页面上调用仪表板函数。
echo $admin->dashboard();
上面总是返回 null,我假设它是因为在返回显示 $code 之前它在函数中更改为 null?
我该如何解决这个问题?
I have a function which displays current admin log in information which also displays feedback messages contained in a session variable.
I had it setup so the session variable would be set to null straight after it was displayed. However in the implementation I have the function displaying the variable displays it like so:
function loginInfo()
{
$code .= 'You are logged in as bob.';
$code .= 'msg:'.$_SESSION['msg'];
$_SESSION['msg'] = null;
return $code;
}
function breadCrumbs($section = '')
{
$html .= $this->loginInfo();
$html .= '<h1><a href="/admin">Dashboard</a> > '.$section.'</h1>';
return $html;
}
function dashboard()
{
$html .= $this->breadCrumbs('');
$html .= '<ul>';
$html .= etc..
}
-----------
$_SESSION['msg'] = 'message here';
header(Redirect "/admin");
exit();
then the dashboard function is called on the new page.
echo $admin->dashboard();
The above always returns null, I'm assuming its because its changed to null in the function before the $code is displayed from the return?
How can I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你的代码很好。
您必须在其他地方进行搜索。
在代码中搜索 2 次
loginInfo();
即可找到它No, your code is pretty fine.
You must search in another places.
Search for 2 occurences of
loginInfo();
in your code and you'll get it