2017 © Pedro Peláez
 

library db-session

Store session in database in zend framework 2

image

mohit-singh/db-session

Store session in database in zend framework 2

  • Friday, July 4, 2014
  • by Mohit-Singh
  • Repository
  • 1 Watchers
  • 6 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DbSession

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)

The Versions

04/07 2014

dev-master

9999999-dev https://github.com/Mohit-Singh/DbSession

Store session in database in zend framework 2

  Sources   Download

The Requires

  • php >=5.3.0

 

by Mohit K Singh

zf2 session zf2 db session