In some instances, for example when a user logs out, all session data should be removed, and the session must be closed. Of course, it would be possible to loop through $_SESSION with foreach and then set each value to an empty string or null, but there is a quicker way: Call session_destroy(). After that, all data in the current session is destroyed, as the function name suggests. Removing All Session Data (session_destroy.php)<?php session_start(); echo 'Before: <pre>'; print_r($_SESSION); echo '</pre>After: <pre> '; session_destroy(); print_r($_SESSION); echo '</pre>'; ?> |