There seems to be a considerable amount of confusion about the use of PHP sessions and their destruction. So here are my comments on this topic (with reference and links to the PHP manual), which I hope will at least help some people clarify things:
: available in all sections of a script without the need to reference it through $ GLOBAL variables.
When used, all superglobals have a session ID. However, it will be deleted after all variables associated with the superglobal have been deleted.
$ _SESSION> br>
: Superglobals in the form of associative arrays, e.g.: $ SESSION[“tent”], As associative arrays, these are persistent, ie: always available and can be referenced in all areas of a script; However, the associated arrays can be deleted or destroyed.
: Enables global referencing of a variable with the prefix global. ie: the varible global $ testGlobal The script on one page can be referenced by a script on another page without having to re-specify the value of $ testGlobal on the other pages.
: similar, global $ testGlobal could be used to refer to a function, and this function could again contain a superglobal or a $ GLOBAL (superglobal in the form of an associative array).
: Alternative, global $ testGlobal can be expressed in the form $ GLOBALS[‘testGlobal’],
: all global, no matter if expressed as global $ someVariable or in the form
$ GLOBALS[‘someVariable’], have a session ID that must be used in conjunction with session_destroy () if the session is to be completely destroyed.
: These are variables that exist only in the context of the current script. e.g.: $ someValue and can not be set ().
not set ()
: can only be used to destroy local variables, so that $ testGlobal can be destroyed with unset ($ testGlobal), but not if it was originally created via "global $ testGlobal". This can also be used to delete individual instances of session variables, but should not be used as a method of deleting all or multiple instances of session variables.
: not set () should only be used for local variables and not for deleting all variables within a specific global range. This can therefore be used for deletion exam from $ _SESSION[‘test’]and effectively destroy the session at the same time, but would not destroy the global one global $ testGlobalbecause the underlying global continues to exist due to the subtle differences between global / $ GLOBALS and superglobals.
: $ _SESSION = array () should be used to delete all or some but not all of the variables in a session (however, as this is an associative array, there are alternative methods that work); It can also be used for deletion
: session_destroy () does just that. If you work with a superglobal, the session is effectively destroyed by deleting or disabling its variables. Otherwise, the session will persist if it is a non-superglobal global session unless destroyed, even if all variables have not been set or destroyed.
For non-global global, whether as global or in the form $ GLOBALS[”], these can be destroyed with the session id in conjunction with session_destroy (), e.g.: session_destroy (& # 39; cvxczvillq9f3pj08vjb1 & # 39;,
session_reset (): Reinitialize session array with its original values
session_regenerate_id (): Update the current session ID with a newly generated one