I have searched many questions regarding session_destroy
and the often response from the answerers involve quoting directly from the PHP manual which states the following:
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.
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.
In a question asking "What is the difference between session_unset() and session_destroy() in PHP?", the answerer mentions about $_SESSION
variable and session storage but never go deep enough.
I think a lot of confusion arising from the function session_destroy
is due to the lack of understanding regarding session data and mixing it up with $_SESSION
variable. I would like to know what is the actual purpose of session data if $_SESSION
variable already contains that data?
Thanks.