Page 1 of 1

Can't destroy Session!

Posted: Sun Oct 20, 2002 3:41 pm
by lnetzel
I made this session based login script setting $_SESSION['username'] to verify user agaist... now I want to create my logout logic and figured if I destroy my session the variable will dissapear but... I can't destroy my session

I have a script with only this code:
<?
session_destroy();
?>


and get the error:
"Warning: Trying to destroy uninitialized session in logout.php on line 2"

What does this mean? Or is this not the proper way to logout

thank you/
Lars Netzel

Posted: Sun Oct 20, 2002 3:45 pm
by Takuma
Yes I know I had this problem once,
add session_start() before session_destroy()...

Posted: Sun Oct 20, 2002 3:48 pm
by Heavy
Try this:

Code: Select all

unset($_SESSION);
Also you might want to enable session.auto_start = 1 in your php.ini

This worked!

Posted: Sun Oct 20, 2002 4:07 pm
by lnetzel
This might have been overkill but it worked

Session_start();
Session_unset();
session_destry();

/Thank you!

Posted: Mon Oct 21, 2002 6:09 am
by Takuma
If you are using PHP 4.1+ use $_SESSION it's better than session_register() etc, it's more reliable...