dev-master
9999999-dev https://github.com/Mohit-Singh/DbSessionStore session in database in zend framework 2
The Requires
- php >=5.3.0
by Mohit K Singh
zf2 session zf2 db session
Wallogit.com
2017 © Pedro Peláez
Store session in database in zend framework 2
Store Session in database in ZF2., (*1)
How To Use, (*2)
This a very simple module to store all your session data in your database. for this create a table using the following schema., (*3)
CREATE TABLE `session` ( `id` char(32) NOT NULL DEFAULT '', `name` varchar(255) NOT NULL, `modified` int(11) DEFAULT NULL, `lifetime` int(11) DEFAULT NULL, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Now update the following database requirement in the config, (*4)
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=db_name;host=localhost',
'username' => 'user_name',
'password' => 'xxxxxxx',
'host' => 'localhost',
'dbname' => 'db_name',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
if you already define all these value in you global config please remove them., (*5)
now the module is ready to use. you can set the setting using following config values, (*6)
'session' => array(
'remember_me_seconds' => 2419200,
'use_cookies' => true,
'cookie_httponly' => true,
'cookie_lifetime' => 2419200,
'gc_maxlifetime' => 2419200,
),
Remember if you set "use_cookies" to "false" then every time application will create a new session in database and your session data will removed., (*7)
Store session in database in zend framework 2
zf2 session zf2 db session