With my logout button

Posts 1–4 of 4 · Page 1 of 1
With my logout button
okay on index.php i have

Code:
if(isset($_GET['logoff']))
{
	$_SESSION = array();
	session_destroy();
	
	header("Location: login.php");
	exit;
}
and farther down i have
Code:
<a href="?logoff">Log off</a>
and when i click logout it just wont log me out..

What am i doing wrong?
Meh whenever I want to log out I just set my login cookie to the value "notlogged" or something similar, then validate it whenever someone browses around to check if isset($_COOKIE['login']) && $_COOKIE['login'] != "notlogged" but if you read the documentation accompanying session_destroy you will see the following:

Quote Originally Posted by php.net
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.


Reference:
PHP: session_destroy - Manual
To logoff you best use the POST function, and you need to kill specifiec session like "destroy($_SESSION['login'])", and you need the rule "<? session_start() ?> on the first code line, very important!
Something so simple wont work without supportive code.
Code:
Something like destroy($_SESSION['login'])
<? session_starts() >
Or possibly something simply like
Code:
session_destroy()
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?