定制 folded/session 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

folded/session

Composer 安装命令:

composer require folded/session

包简介

Session manipulation utlilities for your web app.

README 文档

README

Session manipulation utilities for your web app.

Packagist License Packagist PHP Version Support Packagist Version Build Status Maintainability TODOs

Summary

About

I created this library to be able to manipulate a session, e.g. setting and getting data, checking if a data is present, ... In a standalone way.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

Features

  • Set and get value by keys
  • Can flash value (which means they can be getted only once)
  • Can remove values by key
  • Can check if a value exist by its key
  • Uses the plain $_SESSION superglobal

Requirements

  • PHP version >= 7.4.0
  • Composer installed

Installation

1. Install the package

In your root folder, run this command:

composer require folded/session

2. Add the setup code

In the script you want to use, call for the session start function:

if (session_status() !== PHP_SESSION_ACTIVE) {
  session_start();
}

// ...

Examples

1. Set a value

In this example, we will set the value in the session.

use function Folded\setSession;

setSession("token", "12345");

2. Get a value by key

In this example, we will get the value of a session key.

use function Folded\setSession;
use function Folded\getSession;

setSession("token", "12345");

echo getSession("token"); // "12345"

3. Check if a value exist by key

In this example, we will check if a value exist by its key.

use function Folded\hasSession;

if (hasSession("token")) {
  echo "has token in session";
} else {
  echo "has not token in session yet";
}

4. Flash a value

Flashing a value consist of telling the session to keep a value for a single usage. In this example, we will set a flash value, then get it once. Any attempt to get it a second time will fail.

use function Folded\flashSession;
use function Folded\getSession;
use function Folded\hasSession;

flashSession("token", "12345");

echo getSession("token"); // "12345"

var_dump(hasSession("token")); // bool(false)

5. Keep a value one more time after being flashed

In this example, we will use the second parameter of getSession() to keep a flashed data one last time after being getted.

use function Folded\getSession;
use function Folded\flashSession;
use function Folded\hasSession;

flashSession("token", "12345");

getSession("token", $keep = true);

var_dump(hasSession("token")); // bool(true)

6. Remove a value by key

In this example, we will set a value, then remove it, and check if it exist.

use function Folded\hasSession;
use function Folded\removeSession;
use function Folded\setSession;

setSession("token", "12345");

var_dump(hasSession("token")); // booll(true)

removeSession("token");

var_dump(hasSession("token")); // bool(false)

Version support

7.3 7.4 8.0
v0.1.0 ✔️
v0.1.1 ✔️
v0.2.0 ✔️
v0.2.1 ✔️
v0.2.2 ✔️

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固