Hi I am using the following code to try and log out users but it is not working, any ideas why? <?php session_start(); if(isset($_SESSION['authenticated'])) unset($_SESSION['authenticated']); echo 'you are not logged in'; ?> The code I used to start the session is: $_SESSION['authenticated']=true; And that seems to work with the log in but I am unable to log out now. Also for the following code how would I then remove the cookie? setcookie('username', $_POST['username'], time()+60*60*24*365, 'www.website.com'); setcookie('password', $_POST['password'], time()+60*60*24*365, 'www.website.com'); I came up with: $past = time() - 100; setcookie(username, gone, $past); setcookie(password, gone, $past); Sorry if I am completely wrong, I am new at this! Thanks for any help
You should not store passwords in plain text in cookies. For deleting cookies your code is correct, but I would use an even earlier date. Just pass 0 in instead of $past. Try setting $_SESSION['authenticated'] to false instead of unsetting. Also, if you are redirecting after unsetting, you need to write back the data to the file, otherwise the redirect cancels the save.
if(isset($_SESSION['authenticated'])) unset($_SESSION['authenticated']); From above you can use to check the cookies, if they exists it read them, if they don't simply it gives error that you are not logged in.
if(isset($_SESSION['authenticated'])) unset($_SESSION['authenticated']); use this i think this will help you
dont make things complicated. destroy all sessions upon logout session_start(); session_destroy(); header("/");