PHP sessions variables are very easy to work with and are very handy when working with settings across page refreshes. With a PHP session, you can set a variable on one page and use it on the next or twenty pages or a hundred or more down. The only thing that could break your session is if the visitor voluntarily terminates it or you direct them to another website. Sessions can also time out either by the assigned default in your php.ini file or by whatever value you assign within php.
Assigning PHP session timeout within a PHP document:
When using sessions you must first initiate it. In most cases you will want to do this towards the top of the document.
Initiating a PHP session:
Once you have initiated your session its easy to assign session variables. Session varaibles are assigned in about the same way you would assign an array value. PHP session values can include strings or arrays multi or single dimensional.
Assigning a PHP session variable:
$_SESSION['cookie'] = 'chocolate';
If you assign a session variable that you no longer want to use you can simply unset that value.
Unsetting a PHP session variable:
If you are finished working with the session you can terminate it. This can be useful if your users are logged in and you want all of their current session data to be cleared.
Terminating a PHP session:
This is just an introduction to PHP sessions, much more will be covered in the future.