0

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by gilgil2
0

ig guessing its when a user presses a logout button or something

if(logout == "yes"){

// use what you have to kill the cookies
    $past = time() - 100;
    setcookie(username, gone, $past);
    setcookie(password, gone, $past);

// also need to kill the session
unset($_SESSION['authenticated']);

// then refresh the page
header( 'Location: ./index.php' )


}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.