jayc89/php-mysql-session-handler

此包已被废弃,不再维护。作者建议使用 jamiecressey/php-mysql-session-handler 包。

MySQL PHP Session Handler

0.0.1 2015-10-06 19:03 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:44:01 UTC


README

Latest Stable Version Total Downloads Bitdeli Badge

此仓库包含一个使用 MySQL 作为后端的自定义 PHP 会话处理器。该类已成功通过 PHP-FPM 和 HHVM 测试。要开始使用,建议(但不是必需的),此类与 PHP-MySQL-PDO-Database-Class 一起使用。

如何安装

使用 Composer

在项目根目录下创建一个 composer.json 文件

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

然后运行以下 composer 命令

$ php composer.phar install

如何使用

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();

作者

Jamie Cressey

许可协议

MIT 公共许可协议