duanbi2003 2011-09-10 09:08
浏览 52
已采纳

如何返回会话变量并在下次刷新后呈现它后直接清除它?

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> &gt; '.$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?

  • 写回答

1条回答 默认 最新

  • du5114 2011-09-10 09:12
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大