miladrahimi/phpsession
最新稳定版本:1.6
Composer 安装命令:
composer require miladrahimi/phpsession
包简介
Free PHP session tools for neat and powerful projects!
README 文档
README
Free PHP session tools for neat and powerful projects!
Documentation
PHPSession is a tiny package for using sessions in Object Oriented and more secured approach.
There is a class named Session which you interact with to access an manipulate sessions.
Installation
Using Composer
It's strongly recommended to use Composer to add PHPSession to your application. If you are not familiar with Composer, The article How to use composer in php projects can be useful. After installing Composer, go to your project directory and run following command there:
composer require miladrahimi/phpsession
Or if you have composer.json file already in your application,
you may add this package to your application requirements
and update your dependencies:
"require": {
"miladrahimi/phpsession": "~1.6"
}
composer update
Manually
You can use your own autoloader as long as it follows PSR-0 or
PSR-4 standards.
In this case you can put src directory content in your vendor directory.
Getting Started
It's so easy to work with!
use MiladRahimi\PHPSession\Session;
$session = new Session();
$session->set("Singer", "Pink Floyd");
echo $session->get("Singer");
- Because of being compatible with dependency injection, new version is not based on Single Pattern.
- The
get()method will returnnullwhenever the value doesn't exist.
Expiration
In default, the session data is permanent. For security reasons, you should define lifetime for your session. PHPSession would expire the data when their lifetime had finished.
use MiladRahimi\PHPSession\Session;
$session = new Session();
$session->setLifeTime(10); // 10 minutes lifetime!
$session->set("Singer", "Bon Jovi");
- Lifetime unit is minute.
- 0 minute lifetime means unlimited time (it's default value).
- Whenever you change lifetime its lifetime starts to get spent.
UntrustedSession Exception
For security reasons, PHPSession holds user IP and Agent (web browser tool).
It always check this info in any get() call to make sure current user is the real session owner.
UntrustedSession exception will thrown if the user is suspicious.
use MiladRahimi\PHPSession\Session;
use MiladRahimi\PHPSession\UntrustedSession;
$session = new Session();
$session->set("Singer", "Selena Gomez");
try {
echo $session->get("Singer");
} catch (UntrustedSession $e) {
echo "You must sign in again!";
// Log the information...
}
Refresh
PHPSession cannot recognize where exactly need to refresh the user info like IP and agent. To prevent Fixation Session Attack you should refresh sessions every successful sign in request.
$session->refresh();
Session Hijacking and Fixation
PHPSessions is tiny package right now.
It will be better next versions, I promise!
There are some security considerations in this version.
It prevent Session Fixation if you call refresh() method after every successful sing in.
It prevent simple hijackings with holding user info (IP and agent).
In person, I think it's user job to prevent other threats.
But your a able to implement your security approaches with PHPSession,
if you see it like PHP native APIs.
If you have an idea to make PHPSession more secure,
I will appreciate it if you share it with us!
Contributors
Homepage
License
PHPSession is released under the MIT License.
miladrahimi/phpsession 适用场景与选型建议
miladrahimi/phpsession 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「session」 「sessions」 「Session Security」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 miladrahimi/phpsession 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 miladrahimi/phpsession 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 miladrahimi/phpsession 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Secure session middleware for Slim 3 framework
Pop Session Component for Pop PHP Framework
Eloquent Model for the sessions table as created by artisan session:table
Provide a way to secure accesses to all routes of an symfony application.
Non-I/O blocking PHP SessionHandler implementation using Nette/Caching with DI Extension for Nette framework
It's a barebone security class written on PHP
统计信息
- 总下载量: 43
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-10