Can't destroy Session!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lnetzel
Forum Newbie
Posts: 4
Joined: Sun Oct 20, 2002 1:53 pm

Can't destroy Session!

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Yes I know I had this problem once,
add session_start() before session_destroy()...
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Try this:

Code: Select all

unset($_SESSION);
Also you might want to enable session.auto_start = 1 in your php.ini
lnetzel
Forum Newbie
Posts: 4
Joined: Sun Oct 20, 2002 1:53 pm

This worked!

Post by lnetzel »

This might have been overkill but it worked

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

/Thank you!
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

If you are using PHP 4.1+ use $_SESSION it's better than session_register() etc, it's more reliable...
Post Reply