metarush/cookie-sessions
Composer 安装命令:
composer require metarush/cookie-sessions
包简介
Storageless sessions using encrypted cookies as session handler
README 文档
README
Storageless sessions using encrypted cookies as session handler
This library is a drop-in replacement for traditional session stores like filesystem, database, memory, etc.. Use this library to leverage browser cookies as session store and gain scalability without the maintenance of traditional session stores.
Install
Install via composer as metarush/cookie-sessions
Usage
-
Generate an encryption key by typing
vendor/bin/generate-defuse-keyin your terminal. -
Define cookie options (refer to the options parameter of the \setcookie() function).
<?php $options = [ 'path' => '/', 'secure' => true, 'httponly' => true ];
Note: Don't set expires option, this library will use the session.gc_maxlifetime ini directive instead.
- Set the custom session handler on top of your script.
$secretKey = 'replace this with the generated key'; $cookiePrefix = 'your_identifier'; // optional cookie prefix, keep it short, alphanumeric with _ suffix (e.g., XYZ_) $handler = new \MetaRush\CookieSessions\Handler($secretKey, $options, $cookiePrefix); session_set_save_handler($handler, true); session_start();
- Use
$_SESSIONSnormally
$_SESSIONS['foo'] = 'bar';
Notes
- This library uses
defuse/php-encryptionfor encrypting session data in cookies - Keep the
$secretKeyhidden from public - Browsers generally have 4,000 bytes total cookie limit per domain
- An E_USER_WARNING will be thrown if you're trying to set a session variable that is equivalent to >= 4,000 bytes (in encrypted form)
- The limit counts data in encrypted form which is equivalent to roughly 1,900 of unencrypted data
- The limit doesn't account for other session data already written or scripts using cookies on the same domain
- Minimize session/cookie variables per domain to give way to other scripts if applicable
metarush/cookie-sessions 适用场景与选型建议
metarush/cookie-sessions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「cookies」 「sessions」 「session handler」 「encrypted cookies」 「storageless sessions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 metarush/cookie-sessions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 metarush/cookie-sessions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 metarush/cookie-sessions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Pop Session Component for Pop PHP Framework
Eloquent Model for the sessions table as created by artisan session:table
Use Klaro! Consent Manager in Contao CMS
An implementation of a session handler for storing sessions in AWS's DynamoDB, but with no dependencies on the AWS SDK, Guzzle etc
Helper class to easily work with cookies.
统计信息
- 总下载量: 148
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-24