Details of the differences between session_unset and session_destroy

  • 2020-06-07 04:03:47
  • OfStack

session_unset()
Free all $_SESSION variables that are currently created in memory, but do not delete the session file and do not release the corresponding sessionid
session_destroy()
Delete the session file for the current user and release sessionid, leaving the $_SESSION variable in memory
Therefore, to release all the session resources of the user, the following code needs to be executed sequentially:
The program code

<?php
$_SESSION['user'] = 'wangh';
session_unset();
session_destroy();
?>

If you just call session_destroy();
Then echo $_SESSION['user'] is still valuable
That is, the contents of the $_SESSION variable in memory remain
[Session]
session. save_handler = files; The control used to save/retrieve data
session. save_path = C: \ win \ temp; Parameters passed to the controller when save_handler is set to file,
; This is the path where the data file will be saved. Folders should be built in advance
session. use_cookies = 1; Use cookies 1 yes, 0 no
session.name = PHPSESSID
; The name session used in cookie
session. auto_start = 0; Initializes session on request startup
session. cookie_lifetime = 0; For the saving time of cookie in seconds,
; Or 0 until the browser is restarted
session. cookie_path = /; Valid path for cookie
session. cookie_domain =; Valid domain of cookie
session. serialize_handler = php; A controller used to connect data
; php is the standard controller for PHP.
session. gc_probability = 1; Percentage of 'garbage collection (defragmenting) 'process
; The possibility of starting each time session is initialized.
session. gc_maxlifetime = 1440; After the number of seconds indicated here, the saved data will be considered
; 'Shards (garbage)' and are cleared by the gc process.
session. referer_check =; Check the HTTP reference to invalidate the additional ids contained in URLs
session. entropy_length = 0; How many bytes to read from the file
session. entropy_file =; Specify that session id is set up here
; session.entropy_length = 16
; session.entropy_file = /dev/urandom
session. cache_limiter = nocache; Set as {nocache,private,public} to determine HTTP's
; The cache problem
session. cache_expire = 180; The document is out of date after n minutes
session. use_trans_sid = 1; Use transitional sid support, if permitted at compile time
; --enable-trans-sid
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"

Related articles: