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

Recommended Answers

All 2 Replies

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' )


}

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.