krubio/perfect-session
最新稳定版本:v0.1.0
Composer 安装命令:
composer require krubio/perfect-session
包简介
Session Handling
关键字:
README 文档
README
Session Class
The Session class provides a simple and convenient way to manage PHP sessions.
Usage
To use the Session class, create an instance of it and call its methods to get, set, or delete session data.
use PerfectApp\Session\Session; // Create a new session object $session = new Session(); // Set a session variable $session->set('username', 'johndoe'); // Get a session variable $username = $session->get('username'); // Delete a session variable $session->delete('username');
By default, the Session class uses the $_SESSION superglobal to store session data. You can also pass an array of session data to the constructor if you want to use a different session data source.
// Create a session object using a custom session data array $sessionData = [ 'username' => 'johndoe', 'email' => 'johndoe@example.com', ]; $session = new Session($sessionData); // Get a session variable $username = $session->get('username'); // Delete a session variable $session->delete('username');
Methods
__construct(array|null $sessionData = null)
Creates a new Session object.
Parameters
$sessionData(optional): An array of session data to use instead of$_SESSION.
get(string $key): mixed|null
Gets a session variable by key.
Parameters
$key: The name of the session variable to get.
Returns
The value of the session variable, or null if the variable does not exist.
set(string $key, mixed $value): void
Sets a session variable by key.
Parameters
$key: The name of the session variable to set.$value: The value to assign to the session variable.
delete(string $key): void
Deletes a session variable by key.
Parameters
$key: The name of the session variable to delete.
统计信息
- 总下载量: 195
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-28