php session unset

Soldato
Joined
6 Feb 2004
Posts
20,674
Location
England
i'm sure i've done something like this many moons ago but i'm struggling at the moment. :o

my problem is thus..

Code:
<?php
session_start();
?>
//html gibberish + form
<?php
if(isset($_SESSION('message'])) {
    echo $_SESSION['message'];
    unset($_SESSION['message']);
}
?>
//html stuff to finish

if i remove the unset then it works. but if i leave it in, it's preventing the previous line from displaying. even if i use print_r($_SESSION) right after session_start(), using unset right on down the page prevents it from showing there? i'm confused... :p

edit: i seem to have sorted this myself by adding ob_start() directly after session_start(). this is more luck than judgement though. i have no idea what i'm doing. :D

edit2: what little luck i had seems to have run out. without making any changes, it's not working anymore. :/
 
Last edited:
Soldato
OP
Joined
6 Feb 2004
Posts
20,674
Location
England
well spotted but that's just a typo in the example i posted here. the page wouldn't even display if that was in my real code..

Code:
Parse error: syntax error, unexpected ']' in D:\Documents\htdocs\index.php on line 70

all i wanted in my message was confirmation that a file had been uploaded ok so to get that without sessions, i wrote a few lines of code to display the contents of the folder along with file modification dates. :)
 
Soldato
OP
Joined
6 Feb 2004
Posts
20,674
Location
England
i think it's fair to say it was definitely an error somewhere in my code.

i just tried this and it works exactly as i would expect it to. :o

Code:
<?php
session_start();
$_SESSION['message'] = 'hello';
echo $_SESSION['message'];
unset($_SESSION['message']);
if(empty($_SESSION['message'])) echo "<br>message cleared";
?>

i also tested it by mixing it up with some html like my problematic script and it still worked.
 
Back
Top Bottom