Zend Framework 2 module for storing sessions in database
Clone into ./vendor/
.
- Enable the module in your
application.config.php
file:
<?php
return array(
'modules' => array(
// ...
'BitDbSession',
),
// ...
);
- Create session table in your database:
CREATE TABLE `session` (
`id` char(32) NOT NULL DEFAULT '',
`name` char(32) NOT NULL DEFAULT '',
`modified` int(11) DEFAULT NULL,
`lifetime` int(11) DEFAULT NULL,
`data` text,
PRIMARY KEY (`id`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Simply define your session configuration in one of your configuration files, for example config/autoload/session.global.php
:
<?php
return array(
'session' => array(
'table_name' => 'session',
'config' => array(
'class' => 'Zend\Session\Config\SessionConfig',
'options' => array(
'name' => 'your_session_name',
'remember_me_seconds' => 2592000,
'cookie_lifetime' => 2592000,
'gc_maxlifetime' => 2592000,
'use_cookies' => true,
),
),
'storage' => 'Zend\Session\Storage\SessionArrayStorage',
'validators' => array(
array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
),
),
),
);