carry0987/session-manager
Composer 安装命令:
composer require carry0987/session-manager
包简介
Flexible and secure session management for PHP. This library provides an object-oriented wrapper for PHP's native session handling functions, implementing SessionHandlerInterface for easy integration with existing projects. It also comes with additional features like session encryption and database
README 文档
README
Modern PHP Session Management Library
Introduction
SessionManager is a modern PHP session management library that provides an object-oriented wrapper around PHP's native session handling functions. It implements the SessionHandlerInterface, allowing for easy integration with existing projects. Additionally, it offers extra features such as session encryption and database storage handlers for scalable applications.
Features
- Object-oriented session management.
- Protection against session fixation attacks.
- Automatic handling of session expiration.
- CSRF token generation and validation mechanisms.
- Easy integration into existing projects or frameworks.
- Support for custom session names and cookie parameters.
Installation
You can install SessionManager via Composer:
composer require carry0987/session-manager
Usage
Here is a basic example of how to use SessionManager:
require 'vendor/autoload.php'; use carry0987\SessionManager\SessionManager; // Create a SessionManager instance, you may optionally supply a custom session name and cookie parameters $sessionManager = new SessionManager('MY_SESSION_NAME', [ 'lifetime' => 3600, // Cookie lifetime 'secure' => true, // Send only over HTTPS 'httponly' => true, // Accessible only through the HTTP protocol 'samesite' => 'Strict' // Strict same-site policy ]); // Set a session variable $sessionManager->set('username', 'user123'); // Retrieve a session variable $username = $sessionManager->get('username'); // Destroy the session $sessionManager->destroy(); // Renew the session $sessionManager->renew('MY_SESSION_NAME');
Security Features
- Session fixation attack protection:
SessionManagerregenerates the session ID periodically. - Session expiration mechanism: Sessions automatically expire after a period of inactivity.
- CSRF protection: Generates and validates CSRF tokens.
- Secure cookie parameters: Cookies are marked as HttpOnly and Secure by default to enhance security.
API Reference
Here is a list of methods provided by SessionManager:
set($key, $value): Set a session variable.get($key): Get a session variable.exists($key): Check if a session variable exists.remove($key): Remove a session variable.destroy(): Destroy the session.- For more detailed methods and usage instructions, see the code comments.
Contributing
If you have any suggestions for improvement or feature requests, please open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for more information.
carry0987/session-manager 适用场景与选型建议
carry0987/session-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 carry0987/session-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carry0987/session-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-09