omatamix/session-lock
Composer 安装命令:
composer require omatamix/session-lock
包简介
Securely manage and preserve session data.
README 文档
README
Installation
The best way to install Session Lock is through composer. If you do not have composer installed you can install it directly from the composer website. After composer is successfully installed run the command line code below.
composer require omatamix/session-lock
Usage
Session Manager
The session manger comes with a simple api.
use Omatamix\SessionLock\SessionManager; // Construct a new session manager. $session = new SessionManager();
Start or resume a session.
$session->start();
Check to see if our session is running.
if ($session->exists()) { echo "The session is running!"; }
The put method sets a session variable.
$session->put('hello', 'world');
This checks to see if this session variable is set.
if ($session->has('hello')) { echo "The session variable exists."; }
The delete method deletes a session variable.
$session->delete('hello');
The get method gets the session variables value.
echo "Hello " . $session->get('hello') . "!";
The flash method does the same as get but flash will delete the session variable after retrievale.
echo "Hello " . $session->flash('hello') . "!";
Stop a session.
$session->stop();
Session Regeneration
It is very easy to update the current session id with a newly generated one.
$session->regerate();
Session Fingerprinting
This session manager comes with a built-in session fingerprinting which in a way improves session security. When you create a session handler instance, session fingerprinting is enabled by defualt, it binds your remote ip and user agent. If you do not want this enabled you can turn it off with.
$session = new SessionManager([ 'fingerprinting' => false, ]);
You can also disable binding the remote ip or user agent like this.
$session = new SessionManager([ 'bind_ip_address' => false, // If set to true we will bind the ip address else dont. 'bind_user_agent' => false, // If set to true we will bind the user agent else dont. ]);
If you are using a trusted proxy you can set the remote ip with this.
$session = new SessionManager([ 'use_ip' => '127.0.0.1', ]);
Session Handlers
You can also set how you session information is stored using session handlers,
use Omatamix\SessionLock\SessionHandlers\CacheSessionHandler; $session = new SessionManager(); $session->setSaveHandler(new CacheSessionHandler(/** A `psr/cache` or `psr/simple-cache` pool. */));
Supported
Omatamix\SessionLock\SessionHandlers\CacheSessionHandler::classOmatamix\SessionLock\SessionHandlers\CookieSessionHandler::classOmatamix\SessionLock\SessionHandlers\DatabaseSessionHandler::classOmatamix\SessionLock\SessionHandlers\NullSessionHandler::class
Encryption Adapters
This library also includes encrypted session handlers.
use Defuse\Crypto\Key; use Omatamix\SessionLock\Encryption\Adapter\Defuse; use Omatamix\SessionLock\Encryption\Encrypted; $session = new SessionManager(); $session->setSaveHandler(new Encrypeted(new CacheSessionHandler(/** A `psr/cache` or `psr/simple-cache` pool. */), new Defuse(Key::createNewRandomKey())); // All session data will now be encrpyted using the `defuse` adapter.
Supported
Omatamix\SessionLock\Encryption\Adapter\Defuse::classOmatamix\SessionLock\Encryption\Adapter\Halite::class
Session Config
You can also pass session configuration through the session manager constructor method.
$session = new SessionManager([ 'config' => [ 'use_cookies' => true, 'use_only_cookies' => true, 'cookie_httponly' => true, 'cookie_samesite' => 'Lax', 'use_strict_mode' => true, ] ]);
Security Vulnerabilities
If you discover a security vulnerability within Session Lock, please send an e-mail to Nicholas via omatamix@gmail.com. All security vulnerabilities will be promptly addressed.
Contributing
All contributions are welcome! If you wish to contribute.
License
This project is licensed under the terms of the MIT License.
omatamix/session-lock 适用场景与选型建议
omatamix/session-lock 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 omatamix/session-lock 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 omatamix/session-lock 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-10