Giter VIP home page Giter VIP logo

php-mysql-session-handler's Introduction

PHP MySQL Session Handler

Latest Stable Version Total Downloads Bitdeli Badge

This repository contains a custom PHP session handler using MySQL as a backend. The class has been tested successfully using PHP-FPM and HHVM. To get started, it is recommended, although not required, this class is used in conjunction with PHP-MySQL-PDO-Database-Class.

How to Install

using Composer

Create a composer.json file in your project root:

{
    "require": {
        "jamiecressey/php-mysql-session-handler": "dev-master"
    }
}

Then run the following composer command:

$ php composer.phar install

How to use

CREATE TABLE IF NOT EXISTS `sessions` (
    `id` varchar(32) NOT NULL,
    `timestamp` int(10) unsigned DEFAULT NULL,
    `data` mediumtext,
    PRIMARY KEY (`id`),
    KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
require 'vendor/autoload.php';
$handler = new \JamieCressey\SessionHandler\SessionHandler();

// Pass DB details to create a new MySQLi connection
$handler->setDbDetails('localhost', 'username', 'password', 'database');
// OR alternatively, inject an existing MySQLi resource
// $db = new Db(); // See: https://github.com/jamiecressey/php-mysql-pdo-database-class
// $handler->setDbConnection($db);

$handler->setDbConnection($db);
$handler->setDbTable('sessions');
session_set_save_handler($handler, true);
session_start();

Authors

Jamie Cressey

License

MIT Public License

php-mysql-session-handler's People

Contributors

jamiecressey avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.