Page 1 of 1

Logout Issue

Posted: Wed Oct 29, 2014 5:19 pm
by Epiales
Not sure why it just started happening, but when I click logout, it takes the person to logout.php and it should take them back to the index.... It was working fine, but just started doing this.

LOGOUT.PHP

Code: Select all

<?php
session_start();
// Set Session data to an empty array
$_SESSION = array();
// Expire their cookie files
if(isset($_COOKIE["id"]) && isset($_COOKIE["user"]) && isset($_COOKIE["pass"])) {
setcookie("id", '', strtotime( '-5 days' ), '/');
    setcookie("user", '', strtotime( '-5 days' ), '/');
setcookie("pass", '', strtotime( '-5 days' ), '/');
}
// Destroy the session variables
session_destroy();
// Double check to see if their sessions exists
if(isset($_SESSION['username'])){
//this should never occur
header("location: message.php?msg=Error:_Logout_Failed");
} else {
header("location: index.php");
exit();
} 
I have also tried and replaced the index.php with the actual URL to the index.php, but it didn't work either.

Re: Logout Issue

Posted: Wed Oct 29, 2014 10:28 pm
by Jackolantern
Try echo'ing out $_SESSION['username'] after calling session_destroy(). Apparently there is still something causing isset() to return true.

EDIT: Note you will probably need to comment out the header calls to do this, since you will get an error if you send a header after any data is sent to the client.

Re: Logout Issue

Posted: Thu Oct 30, 2014 7:16 am
by Winawer
I don't really understand the question but there's a problem in the code: setcookie breaks header redirects unless you use output buffering.

Re: Logout Issue

Posted: Thu Oct 30, 2014 7:27 am
by MikuzA
$_SESSION variables are still set in the same page after calling session_destroy().


try doing,
unset($_SESSION);
session_destroy();


or

as PHP.net suggests,

$_SESSION = array();
session_destroy();

and there's some extra stuff also mentioned in the example at php.net on session destroying>
http://php.net/manual/en/function.sessi ... ample-3902

Re: Logout Issue

Posted: Thu Oct 30, 2014 10:29 am
by Epiales
Okay, I think I have it all working now. maybe lol.... if someone doesn't mind just checking, would be great!

http://gameplaytoday.net

test@test.com
test

thanks for the help

EPI

Re: Logout Issue

Posted: Thu Oct 30, 2014 11:13 am
by Jackolantern
Man, it has been a long time since I used PHP :P I don't remember so much about it

Re: Logout Issue

Posted: Thu Oct 30, 2014 11:42 am
by Epiales
Jackolantern wrote:Man, it has been a long time since I used PHP :P I don't remember so much about it
LOL, it's the only language I really know. And what I know, I've learned here lol! U guys are awesome.