Page 1 of 1

session_destroy()

Posted: Thu Feb 18, 2010 10:23 am
by aravona
I have a working login - and I want a log out button.

What I've got for my button is:

Code: Select all

<form action='logout.php' method='post'><input name='Logout' type='Submit' value='Logout' /></form>
And logout.php:

Code: Select all

<?php   
session_destroy(); 
echo "You have logged out";
echo "<head><meta HTTP-EQUIV='REFRESH' content='10; url=index.html'></head>";
?>
But its not working, it gives this: Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in D:\wamp\wamp\www\stuff\logout.php on line 2

My session is started elsewhere, so what do I need to do in order to destroy my session and get my user to log out?

Re: session_destroy()

Posted: Thu Feb 18, 2010 10:25 am
by requinix
You have to start the session before you can destroy it.

Re: session_destroy()

Posted: Thu Feb 18, 2010 10:32 am
by aravona
ok lol, that seems a bit odd but it did work :) my user does log out now :)

Thank you kindly :)

Re: session_destroy()

Posted: Thu Feb 18, 2010 10:50 am
by requinix
aravona wrote:ok lol, that seems a bit odd but it did work
PHP doesn't know which session it should destroy until you call session_start. That's when it looks at the user's cookies to look up the session to use.