packfire/session

此包已被弃用,且不再维护。未建议替代包。

使用 Packfire Session 库使 PHP 会话变得简单。

1.2.0 2014-02-06 15:11 UTC

This package is not auto-updated.

Last update: 2021-05-23 22:44:58 UTC


README

#Packfire Session

使用 Packfire Session 库使 PHP 会话变得简单。

Packfire Session 旨在通过改进安全性能,抽象并提升 PHP 会话的行为,以便于开箱即用的使用。

##安装 使用 Composer 将 Packfire Session 包含到您的项目中。

{
    "require": {
		"packfire/session": "1.0.*"
	}
}

运行 Composer 以安装 Packfire Session 并用于您的项目。

$ composer install

##使用

Session 类是我们可以从其工作会话的主要类。

初始化会话

<?php
use Packfire\Session\Session;
use Packfire\Session\Storage\SessionStorage;

$session = new Session(new SessionStorage());
if (!Session::detectCookie()) { // only register session if cookie is not found.
	Session::register(); // session_start();
}

重新生成新的 Session ID(当用户登录/登出时推荐使用,以提升安全性)

$session->regenerate();

使会话无效(会话保持注册,但所有值都被清除,会话 ID 重新生成)

$session->invalidate();

销毁会话(完全移除会话 ID)

Session::unregister();

会话桶是限制会话变量的好方法。要开始使用会话桶

$bucket = $session->bucket('form');
$bucket->set('txtName', $_POST['txtName']);