Windwalker Session package

Installs: 799

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 4

Forks: 1



Windwalker Session package provides a simple interface to manage session data.

Installation via Composer

Add this to the require block in your composer.json.

    "require": {
        "windwalker/session": "~3.0"

Getting Started

use Windwalker\Session\Session;

$session = new Session;


$session->set('flower', 'sakura');

$data = $session->get('flower', 'default');

$session->exists('animal'); // bool

Set Expire Time

$session->setOption('expire_time', 20); // Minutes


Destroy Session


// Restart

Fork Session

Fork session to generate a new id.


Session Bags

Session bag is a data storage to store data, we can add many bags to Session object and access them.

Use Default Bag

Get Default Bag


Get data from default bag.


// OR

Use Custom Bags

use Windwalker\Session\Bag\SessionBag;

$session->setBag('mybag', new SessionBag);

// Get data
$myBag = $session->getBag('mybag');

$myBag->set('foo', 'bar');
$myBag->get('foo', 'default');

We can use Namespace to get data from bags

// Get form default bag
$session->get('foo', 'default', 'mybag');

// Get from mybag
$session->get('foo', 'default', 'mybag');

// Set to mybag
$session->set('foo', 'bar', 'mybag');


Flash bag is a data temporary storage, if we take data out, the bag will be clear.

$session->addFlash('Save success.', 'info');
$session->addFlash('Login Fail.', 'error');

// Take all messages and clear
$allMessages = $session->getFlashes();

// Peek messages but don't clear

Auto Expired Flash Bag

We can make all flash data clear when every page loaded, use AutoExpiredFlashBag instead FlashBag.

$session = new Session(null, null, new AutoExpiredFlashBag);


Windwalker Session provides many handlers to storage session.

use Windwalker\Session\Handler\MemcachedHandler;

$session = new Session(new MemcachedHandler);

Available Handlers

  • ApcHandler
  • DatabaseHandler
  • MemcacheHandler
  • MemcachedHandler
  • NativeHandler
  • WincacheHandler
  • XcacheHandler