PHP session tutorial - Clean and destroy session
In this tutorial I will show you how to work with sessions in PHP. You will learn how to transfer information between pages.
|Name:||PHP session tutorial|
Bookmark PHP session tutorial
Step 5 - Clean and destroy session
PHP session tutorial
Sometimes it is important to remove a session variable or destroy the complete session. Such mechanism is used for example during a user logs out from a site.
To remove a variable from a session is quite easy. You just have to call the unset() function to do this. Now you can extend our example code to unset the username as follows:
You can use the session_destroy() function if you want to remove all session data, but be careful with it.
Previous Step of PHP session tutorial
Tags: php sessions, php, session, session handling
|PHP session tutorial - Table of contents|
|Step 1 - Session basics|
|Step 2 - Most important session parameters|
|Step 3 - Starting a session|
|Step 4 - Check sessions|
|Step 5 - Clean and destroy session|