Skip to content

Using the Session Manager Object

mattbasta edited this page Sep 14, 2011 · 1 revision

Using the Session Manager

The session manager is completely automatic. A session is automatically created the first time a user accesses the site.

Sessions are composed of the following parameters, hashed together:

  1. The user's IP address (to mitigate session hijacking)
  2. A randomly generated value
  3. A secret value kept in the constants file

Usage

In most contexts, a variable called $session is created. Setting any property of this object will store that data in the session. Accessing will retrieve the data from the session. If a property doesn't exist, it will return false.

if(!$session->shown) {
    echo "Hello! This is the first request of your session.";
    $session->shown = true;
}

To close a session, call the $session->destroy() method.

Settings

IXG_KV_SESSIONS
Setting this value to false will use the PHP session handler instead of the Interchange session handler. The $session variable will simply act as a $_SESSION wrapper. Using the Interchange session handler allows sessions to persist across multiple server instances that are serviced by a load balancer (by using a common key value store).
IXG_KV_SESSIONS_TIMEOUT
A timeout value to expire keys after. This should be set to the lifespan of a session.

Disable sessions

In a library, define the constant NOSESSION. Once this constant is defined, a session will not be instantiated. This can also be done from the constants file.

Clone this wiki locally