aloframework/session 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aloframework/session

最新稳定版本:2.0

Composer 安装命令:

composer require aloframework/session

包简介

Redis or MySQL-based session management

README 文档

README

MySQL & Redis-based session management

Latest release API documentation: https://aloframework.github.io/session/

License Latest Stable Version Total Downloads

dev-develop Latest release
Dev Build Status Release Build Status
Coverage Status Coverage Status

Installation

Installation is available via Composer:

composer require aloframework/session

Additional steps for MySQL

MySQL-based sessions require an additional step which is described in setup/MySQL.md.

Usage

All sessions use the same interface (bar the constructor), in this example Redis will be used.

<?php
    
    use AloFramework\Session\RedisSession;
    
    //Make our Redis connection
    $redis = new Redis();
    $redis->connect('127.0.0.1');
    
    //Start our session. The redis parameter can be omitted, in which case the code above will be run automatically
    // within the class
    $sess = (new RedisSession($redis))->start();
    
    //That's it - you can now use the handler just like you would use a regular PHP session.
    $_SESSION['foo'] = 'bar';
    unset($_SESSION['qux']);
    echo $_SESSION['baz'];
    
    //Additionally, you can work directly with the RedisSession object via the ArrayAccess interface and magic
    // getter+setter:
    $sess->foo   = 'bar';
    $sess['foo'] = 'bar';
    unset($sess['foo']);
    echo $sess->foo;
    echo $_SESSION['foo'];

Logging

An instance of \Psr\Log\LoggerInterface should be passed on to the constructor to make use of basic logging (almost everything is debug-level). If one isn't passed on, an instance of \AloFramework\Log\Log will be created with default parameters.

Configuration

Configuration is done via the Configuration class.

  • Config::CFG_TIMEOUT - session lifetime in seconds (defaults to 300)
  • Config::CFG_COOKIE_NAME - how the session cookie will be named (defaults to AloSession)
  • Config::CFG_FINGERPRINT_NAME - the session key which will hold the session-hijacking prevention fingerprint. You cannot set any session keys with the same name as that would invalidate the session. Defaults to _fp_.
  • Config::CFG_PREFIX - how to prefix session keys if using cache-based handlers. Defaults to _alo_sess_.
  • Config::CFG_SESSION_ID_ALGO - hashing algorithm to use for session IDs. Defaults to sha512.
  • Config::CFG_TABLE - table to use if using MySQL-based handlers. Defaults to alo_session.
  • Config::CFG_SECURE - if set to true, the session cookie will only be sent via HTTPS connections (defaults to true).
  • Config::CFG_GC - garbage collection probability. If set to 100 (default) there is a 1/100 (i.e. 1% chance) that a garbage collection event will occur on session start. This is only used with MySQLNoEventSession.
  • Config::CFG_SAVE_CLI - whether to save/write session data in CLI mode (default: false)
  • Config::CFG_TOKEN - The session key to identify token data. You must not set any session values using this key as that would invalidate the tokens. Defaults to _tk_.

统计信息

  • 总下载量: 53
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2015-10-26