First of all you need to start the session with the session_start() function. Note that this function should be called before any output is generated! This function initialise the $_SESSION superglobal array where you can store your data. So for example let's store user name in the session. You can do it as follows:
If you want to display the username you need to start the session again. In this case PHP checks whether session data are sored with the actual id or not. If it can find it then initialise the $_SESSION array with that values else the array will be empty. So a code which displays the username looks like this:
However if you have executed the first example as well then you will never get the message "Set the username" as you have done it in your very first call. If you wait until the session is expired and execute the code again you will get the set message.
PHP Session Tutorial - Clean and Destroy a Session
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: