承接 popphp/pop-session 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

popphp/pop-session

最新稳定版本:4.0.4

Composer 安装命令:

composer require popphp/pop-session

包简介

Pop Session Component for Pop PHP Framework

README 文档

README

Build Status Coverage Status

Join the chat at https://discord.gg/TZjgT74U7E

Overview

pop-session is a component used to manage sessions and session data in the PHP web environment. It includes the ability to also manage namespaces within the session as well as timed-based and request-based expirations.

pop-session is a component of the Pop PHP Framework.

Top

Install

Install pop-session using Composer.

composer require popphp/pop-session

Or, require it in your composer.json file

"require": {
    "popphp/pop-session" : "^4.0.4"
}

Top

Quickstart

You can create a session and store and fetch data from it:

use Pop\Session\Session;

$sess = Session::getInstance();

// Set session values
$sess->foo   = 'bar';
$sess['baz'] = 123;

// Access session values
echo $sess['foo'];
echo $sess->baz;

You can unset session data like this:

unset($sess->foo);
unset($sess['baz']);

And finally, you can destroy the whole session like this:

$sess->kill();

Top

Time-Based

Session values can be made available based on time expiration:

use Pop\Session\Session;

$sess = Session::getInstance();
$sess->setTimedValue('foo', 'bar', 10); // # of seconds

Then, the next request will be successful if it's within the time limit of that session data:

use Pop\Session\Session;

if (isset($sess->foo)) {
    echo $sess->foo;
} else {
    echo 'Nope!';
}

Top

Request-Based

Session values can be made available based on number of requests:

use Pop\Session\Session;

$sess = Session::getInstance();
$sess->setRequestValue('foo', 'bar', 1); // # of requests

Then, the next request will be successful if it's within the set limit of number requests allowed before that session data is expired:

if (isset($sess->foo)) {
    echo $sess->foo;
} else {
    echo 'Nope!';
}

Top

Namespaces

You can store session data under a namespace to separate that data from the global session data:

use Pop\Session\SessionNamespace;

$sessMyApp = new SessionNamespace('MyApp');
$sessMyApp->foo = 'bar'

if (isset($sessMyApp->foo)) {
    echo $sessMyApp->foo;  // Only available under the namespace.
} else {
    echo 'Nope!';
}

Session namespaces can also store time-based and request-based session data:

use Pop\Session\SessionNamespace;

$sessMyApp = new SessionNamespace('MyApp');
$sessMyApp->setTimedValue('foo', 'bar', 10); // # of seconds
$sessMyApp->setRequestValue('foo', 'bar', 1); // # of requests

Top

统计信息

  • 总下载量: 11.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-07-08