Logout Issue

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Logout Issue

Post 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.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Logout Issue

Post 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.
The indelible lord of tl;dr
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Logout Issue

Post 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.
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: Logout Issue

Post 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
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Logout Issue

Post 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
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Logout Issue

Post by Jackolantern »

Man, it has been a long time since I used PHP :P I don't remember so much about it
The indelible lord of tl;dr
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Logout Issue

Post 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.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”