HTTP session is standard feature that allows web servers to maintain user identity and store user-specific data during multiple request/response interactions.

In the Quantum framework the session component provides object-oriented wrappers to access session data. The session manager, SessionManager is a class that is responsible for all aspects of session management.

Quantum comes with 2 session storage drivers:

  • Native - File based
  • Database - Database based

The session driver should be defined in config.php of your local module or in base config.php file with session_driver key, which can benative or database (default is native).

return array(
    'session_driver' => 'database', 

In the Quantum framework there is a session() helper function which is a gateway to SessionManager, which leads through session methods.

Retrieving session data by given key

$data = session()->get($key);


Retrieving all session data

$data = session()->all();


Checking if session contains data with given key, which returns true or false



Storing data in the session

$data = session()->set($key, $value);


Deleting data from session by given key



Deleting whole session data



The Quantum supports `flashdata` which if are set, will only be available in the subsequent request, and is then automatically cleared.

Gets flesh data by given key

$data = session()->getFlesh($key);


Sets flesh data with given key

session()->setFlesh($key, $value));

Storing Sessions in a database

In order to store session data in a database, first we need to update the session_driver value to `database` and then create a table with following structure.

CREATE TABLE sessions (
    id varchar(32) NOT NULL,
    access int(10) unsigned,
    data text,
    PRIMARY KEY (id)

<< Prev Next >>