http://www.phpro.org/tutorials/Introduction-To-PHP-Sessions.html

Simple Session Example

Session Overview:
Session support is a method to preserve data across user requests.

Visitors accessing a web site are assigned a unique id; that is a session id. The session id is either stored in a cookie on the user side (client), or is propagated in a URL.

Using sessions allow data to be stored between requests in the $_SESSION superglobal array. When a visitor accesses your site, PHP will checks whether a specific session id has been sent with the request. If this is the case, the prior saved environment is recreated.

Sessions can be employed in two methods:
  1. cookie based (preferred)
  2. url based (problematic with search engines)
Cookie based: when a session is begun, a cookie is created on the client's machine, with a unique session ID (i.e., SID). Session variables are typically stored on a file on the server that matches the unique session ID.

When a variable is required, the client or browser looks for the file matching the session ID and retrieves the corresponding variables from it. A typical session file stored in the default session file directory could look like this:
sess_fd51ab4d1820aa6ea27a01d439fe9959

This file would contain session information in an array.

Basic Session Functions:
  1. session_start(): begin new or resume existing session
  2. session_register(variable): register one or more global variables with current session
  3. session_id(): set/get session ID
  4. session_unset(): free memory all session variables
  5. session_destroy(): destroy all data registered to session
More Session Functions: http://www.php.net/manual/en/ref.session.php

Session Example:
  1. Begin session
  2. Initialize/set session variable
  3. Use PHP super global $_SESSION to hold value
  4. Recall value on next page
<?php
/*
//Nothing can be sent to the browser before session_start()
//This means no text, not even a newline or a space. 

//This will generate and error!
echo 'This is a bad thing to do';
*/

// begin session
session_start(); 

// initialize super global $_SESSION (array) variable value of 'test'
$_SESSION['myVariable1']='test'; 
$_SESSION['myVariable2']='me'; 
?>
Example:
Process sessions

Notes:
  1. session_start() must be used on every session page.
  2. In most cases, it will be the first line of code on each page.
  3. If a session is not already active, PHP will begin a new session upon adding a new variable to the super global $_SESSION array.
  4. Nothing can be sent to browser before session_start() no text, not even a newline or a space.
Session Handling:
http://www.php.net/manual/en/book.session.php