I am confused by this description. If this function [ session_destroy() ] destroys all session data, then why aren't the global variables associated with the session canceled? Why can we use session variables again?
Session data is the data associated with a session. A session is determined by its name (session name) and its id (session identifier).
Using this function, all these sessions (name + id) are destroyed.
The variable container that allowed you to read / set this data still exists, so you can work with this data (for example, there may be information in the form of the last action, and this is logout, and you want to save information about the last event when logout or in some logs or in the database, so why delete them? It will be counterproductive because you want to quickly destroy (or make) sessions, for example, when you know only read-only access, save session data sa in memory, but end the session already because there is no need to keep it open).
Keep in mind that even these variables are available through $_SESSION , they are no longer part of the session. Perhaps this is the confusing part?
By the way, my description is not entirely correct. PHP internally identifies session data by identifier only so that you can change the name of the session, and session_destroy() would still delete the session data because the session identifier has not changed.
hakre source share