Closing Sessions


 session_destroy() 


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>'; ?> 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net