Analysis of differences between session_unset and session_destroy in php

  • 2020-05-07 19:24:47
  • OfStack

session_unset()
Release all the $_SESSION variables that are currently created in memory, but do not delete the session file and do not release the corresponding session
id

session_destroy()
Delete the session file corresponding to the current user and release session
id, the contents of the $_SESSION variable in memory remain

Therefore, to release all the session resources of the user, the following code needs to be executed in order:
 
<?php 
$_SESSION['user'] = 'lowell'; 
session_unset(); 
session_destroy(); 
?> 

Related articles: