Documentation

Session

Download (pdf)

Overview

In its simplest form, a PHP session allows data to be stored temporarily on the server and accessed throughout a user's time on the site. When that user leaves the site or is inactive for a certain amount of time, the data is destroyed.

The Session class has already taken care of many aspects of session storage. It provides a very simple interface to store and retrieve data from the user's session.

Storing Data

Also, when multiple extensions run on a site, there is a possibility of running into naming conflicts in session variables. For this reason, Session allows for the specification of a namespace that a var should be placed under.

Session::set('cart', $cart, 'uniqueName');

Retrieving Data

Much like in the Request library, a default value can be specified in the get() method as the second argument.

// Return an empty array if no data found
$cart = Session::get('cart', array());

Last modified: