2017 © Pedro Peláez
 

library zf2-cookie-session

Session save handler used to store the session in a cookie

image

locosoftworks/zf2-cookie-session

Session save handler used to store the session in a cookie

  • Thursday, July 10, 2014
  • by moranjk
  • Repository
  • 1 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Cookie Session Handler

Requires

Composer Install

Add the following to composer.json and execute composer update, (*1)

"minimum-stability": "dev",
"require": {
    "locosoftworks/zf2-cookie-session": "dev-master"
}

Usage

To use the session handler in ZF2, you will need to ensure the session is written before any output is returned. This can be achieved by adding a listenter to the SendResponseEvent::EVENT_SEND_RESPONSE event, or use the provided SessionManager. This can be done in your application.config.php, (*2)

'service_manager' => array(
    'invokables' => array(
        'SessionManager' => 'Loco\Session\SessionManager',
    ),
)
````

To encrypt the client side session, you will need to provide your own encryption method that implements `\Loco\Crypt\CipherInterface`.  For more information regarding how to use the provided encryption method, please see the [ZF2 Documentation on Block Cipher](http://framework.zend.com/manual/2.0/en/modules/zend.crypt.block-cipher.html)

$cipher = new \Loco\Crypt\BlockCipher(new \Zend\Crypt\Symmetric\Mcrypt(array('algo' => 'aes'))); $cipher->setKey('This is my application secret key');, (*3)


This will need to be high enough in your stack that it is called before anything else attempts to start the session. The location of this code could very, but placing it at the top of your `onBootstrap` method sholud suffice.

// assuming $sm is your ServiceManager and SessionManager is a Loco\Session\SessionManager $sessionManager = $sm->get('SessionManager');, (*4)

// ClientSessionAdapter is a ZF2 wrapper to the ClientSession $sessionAdapter = new \Loco\Session\SaveHandler\ClientSessionAdapter();, (*5)

// set the cipher $sessionAdapter->setCipher($cipher);, (*6)

$sessionManager->setSaveHandler($sessionAdapter);, (*7)

// the SessionManager NEEDS the EventManager to set up the necessary listeners $sessionManager->setEventManager($eventManager);, (*8)

$sessionManager->start(); ```, (*9)

The Versions

10/07 2014

dev-master

9999999-dev

Session save handler used to store the session in a cookie

  Sources   Download

MIT

The Requires

 

by James Moran