ellipse / session-start
允许使用Psr-7请求和响应进行会话的Psr-15中间件
1.0.3
2018-02-23 14:01 UTC
Requires
- php: >=7.0
- dflydev/fig-cookies: ^1.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
- zendframework/zend-diactoros: ^1.6
This package is auto-updated.
Last update: 2024-08-26 00:15:07 UTC
README
此包提供了一个 Psr-15 中间件,允许使用Psr-7请求和响应进行会话。
需求 php >= 7.0
安装 composer require ellipse/session-start
运行测试 ./vendor/bin/kahlan
使用启动会话中间件
此中间件使用默认的php会话机制,适应Psr-7请求和响应流程。默认的php会话cookie被禁用,会话id通过从Psr-7请求中读取并附加到Psr-7响应中手动存储。
默认情况下,使用 session_name()
和 session_get_cookie_params
返回的值来构建会话cookie。可以给中间件提供一个可选的选项数组,以覆盖这些默认值
- (string) name: 会话cookie名称
- (string) path: 会话cookie路径
- (string) domain: 会话cookie域名
- (int) lifetime: 会话cookie有效期(秒)
- (bool) secure: 是否仅在安全连接中发送会话cookie
- (bool) httponly: 是否只能通过HTTP协议访问会话cookie
当然,可以使用来自ellipse/session-handler的 SessionHandlerMiddleware
来使用自定义的会话处理器。
<?php namespace App; use Ellipse\Session\StartSessionMiddleware; // All middleware processed after this one will have acces to the $_SESSION data. // The session cookie name will by 'my_session_cookie'. See above for other options. $middleware = new StartSessionMiddleware([ 'name' => 'my_session_cookie', ]);