user3809875
user3809875

Reputation: 131

php session_destroy() what does it actually do?

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?

Upvotes: 1

Views: 1262

Answers (1)

Prime
Prime

Reputation: 2482

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.

Upvotes: 3

Related Questions