district5/simple-session-store

SimpleSessionStore is a session management library for PHP

1.1.0 2022-01-14 13:06 UTC

This package is auto-updated.

Last update: 2024-04-14 17:56:26 UTC


README

SimpleSessionStore is a session management library for PHP. It was originally part of OhSession.

Class overview:

  • \District5\SimpleSessionStore\Session
    • Controls the basic Session functionality that's needed for applications of any size. The primary goal of this class is to provide a simplistic interface to interact with session data.
  • \District5\SimpleSessionStore\Storage
    • Provides a Session Namespace approach to storing data for a users session.

Usage

  • Example Composer file contents:
    {
      "require": {
          "district5/simple-session-store": ">=1.1.0"
      }
    }  
  • Set a value:
    <?php
    $sess = \District5\SimpleSessionStore\Session::getInstance();
    if ($sess->set('foo', 'bar') === true) {
        // set ok.
    }
  • Get a value:
    <?php
    $sess = \District5\SimpleSessionStore\Session::getInstance();
    $val = $sess->get('foo');
    if ($val !== false) {
        // get ok
    }
  • Remove a key:
    <?php
    $sess = \District5\SimpleSessionStore\Session::getInstance();
    if ($sess->remove('foo') === true) {
        // remove ok
    }
  • Remove all keys:
    <?php
    $sess = \District5\SimpleSessionStore\Session::getInstance();
    if ($sess->removeAll() === true) {
        // remove all ok
    }
  • Destroy the session (and optionally regenerate):
    <?php
    $sess = \District5\SimpleSessionStore\Session::getInstance();
    if ($sess->destroy(true) === true) { // or pass false if you don't want to regenerate a session.
        // destroy ok
    }