1

I am reading about PHP sessions and am in the section of session_destroy().

Manual states:

Destroys all data registered to a session

My question is what data? If this function does not destroy the sessions id/cookie what does it actually destroy?

1 Answer 1

3

When a session is created (session_start) a file is created with a unique identifier that is given to the user as a cookie, when variables in the $_SESSION array are modified or added the temporary file is updated with that information so that it can be used somewhere else on the website.

If the user already has a PHPSESSID cookie (which is what is given to the user when a session is created) PHP will look through all of the session files for a file with the identifier that is the same value as the cookie. If one is found the information in the file will fill $_SESSION, otherwise a new session is created as usual.

session_destroy will delete this file, this is commonly done for when a user logs out of your website so that the (now useless and unnecessary) file isn't taking up space.

Sign up to request clarification or add additional context in comments.

1 Comment

Might be worth nothing that 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." (taken from session_destroy() docs). Other than that, this is a perfect answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.