2017 © Pedro Peláez
 

library mysql-session-handler

MySQL PHP Session Handler

image

programster/mysql-session-handler

MySQL PHP Session Handler

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

PHP 7.0+ MySQL Session Handler

This repository contains a custom PHP session handler using MySQL as a backend. There is also an example codebase using this package., (*1)

How to Install

Using Composer

Install composer if you haven't already (Linux instructions)., (*2)

Navigate to your project's directory and run the following command:, (*3)

composer require "programster/mysql-session-handler"

How to use

It may be easiest just to watch this Youtube demonstration video., (*4)

Below is a script demonstrating how to use this tool., (*5)

require 'vendor/autoload.php';

# Create your MySQL database connection
$db = new mysqli('localhost', 'username', 'password', 'database');

# Create the session handler using that connection and pass it the name of the table
# The handler will try to create it if it doesn't already exist.
$handler = new \Programster\SessionHandler\SessionHandler($db, 'my_sessions_table');

# Tell PHP to use the handler we just created.
session_set_save_handler($handler, true);

# Start your session
session_start();

# Set a session variable.
$_SESSION['my_session_variable'] = 'some data here';

Manually Creating Sessions Table

The tool will try to use the database connection to create the sessions table if it doesn't already exist. If you provide the handler with user credentials that haven't been granted the rights to create tables, you can manually create the table with the following SQL statement:, (*6)

CREATE TABLE IF NOT EXISTS `sessions` (
    `id` varchar(32) NOT NULL,
    `modified_timestamp` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `data` mediumtext,
    PRIMARY KEY (`id`),
    KEY `modified_timestamp` (`modified_timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Authors

License

MIT Public License, (*7)

The Versions

14/01 2018

dev-master

9999999-dev https://github.com/programster/PHP-MySQL-Session-Handler

MySQL PHP Session Handler

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php mysql sessions

14/01 2018

1.0.0

1.0.0.0 https://github.com/programster/PHP-MySQL-Session-Handler

MySQL PHP Session Handler

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php mysql sessions

14/01 2018

0.1.1

0.1.1.0 https://github.com/programster/PHP-MySQL-Session-Handler

MySQL PHP Session Handler

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php mysql sessions

14/01 2018

0.1.0

0.1.0.0 https://github.com/programster/PHP-MySQL-Session-Handler

MySQL PHP Session Handler

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php mysql sessions

06/10 2015

0.0.1

0.0.1.0 http://github.com/jayc89/php-mysql-session-handler

MySQL PHP Session Handler

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

php mysql sessions