开发者

How can I return a session variable and clear it straight after its rendered on the next refresh?

开发者 https://www.devze.com 2023-04-04 02:59 出处:网络
I have a function which displays current admin log in information which also displays feedback messages contained in a session variable.

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.. 
}

-----------

$_SESSIO开发者_如何学CN['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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号