Page 1 of 1

Session will not destroy

Posted: Tue Jul 16, 2002 11:35 am
by finale
I admit I'm a relative newbie to PHP although I have years of experience in other languages. The problem is I have a logout that is supposed to destroy the session completely yet right afterward I go to start a session and it gives me the message:

Notice: Constant sid already defined in /home/finale/public_html/login.php on line 39

Why are there still remnants remaining from the previous session?!

The situation is the newest recommended php on apache running Linux. Cookies are being used for the sessions but I even try to kill the cookie manually. Below is the code:

The main file has this code:
// If logout then close the current session
if (isset($_SESSION['Logout'])) {
unset($_SESSION['Logout']);
Logout($SessionName, $_SESSION['Name'], $_SESSION['StartDate']);
// Create new session
session_name($SessionName);
session_start();
}

and the function Logout looks like this:
function Logout(&$SessionName, &$Name, &$StartDate) {
//remove the local session

// Update login entry in Audit Login to have logout time
$EndDate=date('Y-m-d H-i-s');

$sql = "UPDATE AuditLogin SET EndDate='$EndDate' WHERE (Name='$Name') AND (StartDate='$StartDate')";
DoUpdate($sql);

// set player status to offline
$sql = "UPDATE Players Set Online=0 WHERE Name='$Name'";
DoUpdate($sql);

// unset($Name);
// unset($StartDate);
// session_unset();
session_name($SessionName);
session_start();

// Unset all of the session variables.
$_SESSION = array();
// Destroy the session.
session_destroy();

//remove the client session
// setcookie($SessionName,"",0,"/");
setcookie($SessionName);
}

Yes, I know that passing by reference is not required here :)
The message is for the main file on the line session_start().
I have tried the commented and uncommented setcookie.
The cookie session destruction code is exactly from the php help. Am I missing something here besides my sanity?!

Posted: Tue Jul 16, 2002 11:38 am
by twigletmac
Have you tried doing:

Code: Select all

unset($_SESSION);
instead of

Code: Select all

session_destroy();
Mac

unset($_SESSION) do not work

Posted: Tue Jul 16, 2002 1:12 pm
by finale
Thanks. I just tried it and it did not work. Tried a couple of other ideas like it. One was doing unset($_COOKIE) and the other was unset($_COOKIE[$SessionName]) ;

I displayed the cookie before and after the unset and of course it worked to unset it but the next session_start still says constant sid already defined. I read that there is a constant SID but I don't seem to be able to display it and how do you get rid of it? Shouldn't the session_destroy take care of that?!