php - echo $_SESSION then unset -


i know amateurish question need echo session variable destroy variable.

i've tried this:

if(isset($_session['m'])){    echo($_session['m']);    unset($_session['m']); } 

i've tried session_destroy();

and i've tried unset/destroy session @ end of page (after closing html tag)

the problem i'm having session being destroyed before echoed. i've use code above before without problems. there anyway need do, or have find different solution?

thanks in advance :)

i know it's bit late encountered problem , i'll answer needs it.

i'm pretty sure did redirection using header method same page did unset of session. along these lines:

<?php     if(condition)         $_session = "foo";     header("location: $self"); ?> <html>     ...     <?php echo $_session["foo"]; unset($_session["foo"]); ?>     ... 

the problem header doesn't stop execution of script (as seems) , therefore script continued execute , unset session.

the solution add exit(0) (or flag may need) after header redirection, this:

<?php     if(condition)         $_session = "foo";     header("location: $self");     exit(0); ?> 

it's indeed obscure problem , time consuming 1 well.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -