ellipse/session-validation
Composer 安装命令:
composer require ellipse/session-validation
包简介
Psr-15 middleware allowing to validate the user session ownership
README 文档
README
This package provides a Psr-15 middleware allowing to validate the user session ownership.
Require php >= 7.0
Installation composer require ellipse/session-validation
Run tests ./vendor/bin/kahlan
Using the validate session middleware
This middleware let the developper define a callable producing a client signature from the processed Psr-7 request. This signature is stored in the session so the subsequent request client signatures can be compared to the saved one. When they do not match the session data are unset and the session id gets regenerated.
The callable passed to the middleware is called with the Psr-7 request being processed and must return an associative array containing client specific data. For example it's ip address or user agent.
The middleware can of course be used after the StartSessionMiddleware from ellipse/session-start in order to start a session.
<?php namespace App; use Psr\Http\Message\ServerRequestInterface; use Ellipse\Session\ValidateSessionMiddleware; // This callable must return an associative array. $signature = function (ServerRequestInterface $request) { // Here we assume another middleware set the client ip attribute of the request. return [ 'client-ip' => $request->getAttribute('client-ip'), ]; }; // When using this middleware the session data are tied to the client ip address. // Any attempt to access the session data with a different client ip address would // invalidate the client session. Obvioulsy this middleware should only be processed // after the session has started. $middleware = new ValidateSessionMiddleware($signature);
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-11