2017 © Pedro Peláez
 

library session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

image

voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  • Sunday, June 10, 2018
  • by voku
  • Repository
  • 4 Watchers
  • 17 Stars
  • 14,786 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 62 Forks
  • 2 Open issues
  • 34 Versions
  • 1 % Grown

The README.md

Build Status Coverage Status Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon, (*1)

:crown: Session2DB

A drop-in replacement for PHP's default session handler which stores session data in a database, providing both better performance and better security and protection against session fixation and session hijacking.

Session2DB implements session locking - a way to ensure that data is correctly handled in a scenario with multiple concurrent AJAX requests., (*2)

It is also a solution for applications that are scaled across multiple web servers (using a load balancer or a round-robin DNS) and where the user's session data needs to be available. Storing sessions in a database makes them available to all of the servers!, (*3)

The library supports "flashdata" - session variable which will only be available for the next server request, and which will be automatically deleted afterwards. Typically used for informational or status messages (for example: "data has been successfully updated")., (*4)

Session2DB is was inspired by John Herren's code from the Trick out your session handler article and Chris Shiflett's articles about PHP sessions and based on Zebra_Session., (*5)

The code is heavily commented and generates no warnings/errors/notices when PHP's error reporting level is set to E_ALL., (*6)

Requirements

PHP 7.x with the mysqli extension activated, MySQL 5.x+ (recommanded: mysqlnd extension), (*7)

How to install

composer require voku/session2db

How to use

After installing, you will need to initialise the database table from the install directory from this repo, it will containing a file named session_data.sql. This file contains the SQL code that will create a table that is used by the class to store session data. Import or execute the SQL code using your preferred MySQL manager (like phpMyAdmin or the fantastic Adminer) into a database of your choice., (*8)

*Note that this class assumes that there is an active connection to a MySQL database and it does not attempt to create one!, (*9)

//
// simple (dirty) example
//

<?php
    use voku\db\DB;
    use voku\helper\Session2DB;

    DB::getInstance('hostname', 'username', 'password', 'database');
    new Session2DB();

    // from now on, use sessions as you would normally
    // this is why it is called a "drop-in replacement" :)
    $_SESSION['foo'] = 'bar';
//
// extended example
//

<?php
    use voku\db\DB;
    use voku\helper\DbWrapper4Session;
    use voku\helper\Session2DB;

    // include autoloader
    require_once 'composer/autoload.php';

    // initialize the database connection e.g. via "voku\db\DB"-class
    $db = DB::getInstance(
        'hostname', // e.g. localhost
        'username', // e.g. user_1
        'password', // e.g. ******
        'database', // e.g. db_1
        'port',     // e.g. 3306
        'charset',  // e.g. utf8mb4
        true,       // e.g. true|false (exit_on_error)
        true,       // e.g. true|false (echo_on_error)
        '',         // e.g. 'framework\Logger' (logger_class_name)
        ''          // e.g. 'DEBUG' (logger_level)
    );

    // you can also use you own database implementation via the "Db4Session"-interface,
    // take a look at the "DbWrapper4Session"-class for a example
    $db_wrapper = new DbWrapper4Session($db);

    // initialize "Session to DB"
    new Session2DB(
      'add_your_own_security_code_here', // security_code
      0,                                 // session_lifetime
      false,                             // lock_to_user_agent 
      false,                             // lock_to_ip
      1,                                 // gc_probability 
      1000,                              // gc_divisor 
      'session_data',                    // table_name
      60,                                // lock_timeout 
      $db_wrapper,                       // db (must implement the "Db4Session"-interface)
      true                               // start_session (start the session-handling automatically, otherwise you need to use session2db->start() afterwards)
    );

    // from now on, use sessions as you would normally
    // this is why it is called a "drop-in replacement" :)
    $_SESSION['foo'] = 'bar';

    // data is in the database!

Support

For support and donations please visit Github | Issues | PayPal | Patreon., (*10)

For status updates and release announcements please visit Releases | Twitter | Patreon., (*11)

For professional support please contact me., (*12)

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerfull code style check.
  • Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!

The Versions

10/06 2018

dev-master

9999999-dev http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

29/04 2018

4.0.1

4.0.1.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

23/01 2018

dev-php_old

dev-php_old http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

23/12 2017

4.0.0

4.0.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

22/12 2017

2.1.2

2.1.2.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

22/12 2017

2.1.1

2.1.1.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

20/12 2017

2.1.0

2.1.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

20/12 2017

3.3.0

3.3.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

14/12 2017

3.2.1

3.2.1.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

14/12 2017

3.2.0

3.2.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

14/12 2017

3.1.0

3.1.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

25/11 2017

3.0.0

3.0.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

15/10 2017

2.0.0

2.0.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

03/08 2017

1.2.2

1.2.2.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

22/07 2017

1.2.1

1.2.1.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

21/05 2017

1.2.0

1.2.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

05/05 2017

1.1.0

1.1.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

10/04 2017

1.0.15

1.0.15.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

21/12 2016

1.0.14

1.0.14.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

15/08 2016

1.0.13

1.0.13.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

12/08 2016

1.0.11

1.0.11.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

12/08 2016

1.0.12

1.0.12.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

11/07 2016

1.0.10

1.0.10.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

23/12 2015

1.0.9

1.0.9.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

19/10 2015

1.0.8

1.0.8.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

16/10 2015

1.0.7

1.0.7.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

20/08 2015

1.0.6

1.0.6.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

19/08 2015

dev-analysis-qrGvLz

dev-analysis-qrGvLz http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

13/08 2015

1.0.5

1.0.5.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

24/07 2015

1.0.4

1.0.4.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

17/06 2015

1.0.3

1.0.3.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

11/02 2015

1.0.2

1.0.2.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

28/01 2015

1.0.1

1.0.1.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

database mysql mysqli session locking flash flashdata fixation hijack

26/01 2015

1.0.0

1.0.0.0 http://stefangabos.ro/php-libraries/zebra-session/

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

  Sources   Download

LGPL-3.0

The Requires

 

database mysql mysqli session locking flash flashdata fixation hijack