Jump to content

Completly destroying a session.


WolfRage

Recommended Posts

To finish getting rid of my session I want to do like the manual says.

<?php
session_start();
setcookie(session_name(),'',time() - 36000,'/','127.0.0.1',FALSE,TRUE);
session_destroy();
unset(SID);
?>

But unset(SID); causes this error.

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

Which means it expects a semi colon, translated from Hebrew.

Why do I get this error? The manual says to do this.

http://www.php.net/manual/en/function.session-destroy.php

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
Link to comment
Share on other sites

you should use unset and session_destroy as well.

<?php session_start();

// set a session.
$_SESSION['redarrow']="redarrow";

// echo session

echo $_SESSION['redarrow'];


// let kill session redrrow.

unset($_SESSION['redarrow']);

// let make sure that all session's are killed aswell.

session_destroy();

?>

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

I appreciate the information really. But I knew what it listed already. And as far as destroying it completely that is not true. Because I can still do this:

<?php
session_start();
setcookie(session_name(),'',time() - 36000,'/','127.0.0.1',FALSE,TRUE);
session_destroy();
echo htmlspecialchars(SID);
//unset(SID);
?>

And the echo statement still works.

So how do I unset the SID? And why do I get this super weird error?

I have a plan that I thought of, I will just unlink() the session file and that will be an equivalent of unset(SID) I think.

Link to comment
Share on other sites

Thanks for the kill the cookie comment but again I know. You can also do it this way, which I do.

<?php
setcookie('Tag_Commerce:3',FALSE,time() - 36000,'/','127.0.0.1',FALSE,TRUE);
?>

Don't believe me read the manual. Returning FALSE will attempt to delete the cookie. Now back to the issue at hand.

So how do I unset the SID? And why do I get this super weird error?

Link to comment
Share on other sites

<?php
session_start();
setcookie(session_name(),'',time() - 36000,'/','127.0.0.1',FALSE,TRUE);
setcookie(session_name(),FALSE,time() - 36000,'/','127.0.0.1',FALSE,TRUE);
session_destroy();
unset(SID);
?>

But unset(SID); causes this error.

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

Which means it expects a semi colon, translated from Hebrew.

Why do I get this error? The manual says to do this.

http://www.php.net/manual/en/function.session-destroy.php

So how do I unset the SID? And why do I get this super weird error?

Link to comment
Share on other sites

 

so what i understand SID is always defined and if there use it,

 

but there no way off deleting sid wired.

 

 

<?php session_start();

setcookie(session_name(),'',time() - 36000,'/','127.0.0.1',FALSE,TRUE);

if (defined('SID')) {
session_destroy();
unset($_SESSION);
setcookie(session_name(), -3600);
}

echo htmlspecialchars(SID);

?>

 

 

got told this mate.

SID is an empty string if the session cookie was returned

by the browser; as Mike advised, just use it.

Link to comment
Share on other sites

SID is a constant.  Even if the session is destroyed mid page, the constant will not be undefined (as in the verb, not the state of being).

 

So SID will always be set going down the page even after session_destroy, but the session array will be empty, and the session cookie should automatically be destroyed client side (since PHP should tell the client to get rid of it).

Link to comment
Share on other sites

Ok I have come to realize that there is no way to get rid of or destroy SID like the two of you say. So I am going to submit this to the manual, because I believe the wording is misleading, and instructs a programer to try something that is an error.

 

So PHP Manual = Wrong on this one. http://www.php.net/manual/en/function.session-destroy.php

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

That is unless some one knows something that we do not.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.