metarush/cookie-sessions
最新稳定版本:v3.1.0
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
统计信息
- 总下载量: 144
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-24