How to make a Logout Script
Hey guys. Thanks for all the previous help everyone's given me.
I have another PHP question. Okay, so I've made a PHP login script, basically it's
$username = "blah";
$password = "blah2";
$user = $_POST['username'];
$pass = $_POST['password'];
if($user == $username && $pass == $password)
{
echo "Thank you for logging in. Click to Continue" ;
}
else {
echo "Sorry Incorrect Username or Password";
die();
}
?>```
I was just wondering how you would make a logout script like this. The main reason I'm asking is because I don't know MySQL very well and I would rather code it all in PHP.
Any suggestions?
Thanks in Advanced.
Normally PHP sites use sessions to keep you logged in, then when you want to log out you destroy the session.
DarkMantis wrote: Also, a question on that, which is better: session_destroy(); or unset($_SESSION[]); ? It depends on exactly what you want to achieve. If there are other session variables that you want to maintain (maybe traffic specifics or something), just unset the session variables associated with a logged-in state. Otherwise, just session_destroy(); it's short and sweet.
Also, a mistake a lot of people make with sessions is forgetting to put session_start() at the top of all the pages that they use sessions on. It's not necessary to put it at the top of all pages; the sessions will persist normally with or without it. You only use session_start() if you're going to access / set session vars.