The code above demonstrates how to edit or remove individual session variables, or the entire session. To change a session variable we just reset it to something else. We can use unset() to remove a single variable, or session_unset() to remove all variables for a session. We can also use session_destroy() to destroy the session completely.
<?php // you have to open the session to be able to modify or remove it session_start(); // to change a variable, just overwrite it $_SESSION['size']='large'; //you can remove a single variable in the session unset($_SESSION['shape']); // or this would remove all the variables in the session, but not the session itself session_unset(); // this would destroy the session variables session_destroy(); ?>
By default a session lasts until the user closes their browser. This can be changed in the php.ini file by change the 0 in session.cookie_lifetime = 0 to be the number of seconds you want the session to last, or by using session_set_cookie_params().