承接 initphp/sessions 相关项目开发

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

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

initphp/sessions

最新稳定版本:3.0

Composer 安装命令:

composer require initphp/sessions

包简介

InitPHP Sessions Manager

README 文档

README

Requirements

  • PHP 8.0 or later

Note : Adapters used may have different dependencies.

Installation

composer require initphp/sessions

Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;

Session::createImmutable()
    ->start();
    

Session::set('username', 'admin')
        ->set('mail', 'admin@example.com');
/**
 * OR
 * 
 * $_SESSION['username'] = 'admin';
 * $_SESSION['mail'] = 'admin@example.com';
 */

echo Session::get('username', 'Undefined');
/**
 * OR
 * 
 * echo $_SESSION['username'] ?? 'Undefined';
 */

Redis Adapter Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\RedisAdapter;

$adapter = new RedisAdapter([
    'host'      => '127.0.0.1', // string
    'port'      => 6379, // int
    'timeout'   => 0, // int
    'password'  => null, // null or string
    'database'  => 0,
    'ttl'       => 86400,
    'prefix'    => 'sess'
]);

Session::createImmutable($adapter)
    ->start();

PDO Adapter Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\PDOAdapter;

$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', '');

$adapter = new PDOAdapter(['pdo' => $pdo, 'table' => 'app_sessions']);

Session::createImmutable($adapter)
    ->start();

Example MySQL Table Create SQL :

CREATE TABLE `sessions` (
      `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      `sess_timestamp` timestamp NULL DEFAULT NULL,
      `sess_ip_address` varchar(48) COLLATE utf8mb4_unicode_ci DEFAULT NULL
      `sess_data` text COLLATE utf8mb4_unicode_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `sessions` ADD PRIMARY KEY (`id`);

Memcache Adapter Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\MemCacheAdapter;

$adapter = new MemCacheAdapter([
        'host'          => '127.0.0.1', // string
        'port'          => 11211, // int
        'weight'        => 1, // int
        'raw'           => false, // boolean
        'prefix'        => null, // null or string
        'ttl'           => 86400, // int
]);

Session::createImmutable($adapter)
    ->start();

Cookie Adapter Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\CookieAdapter;

$adapter = new CookieAdapter(['name' => 'sessDataCookieName', 'key' => 'topSecretAppKey', 'ttl' => 86400]);

Session::createImmutable($adapter)
    ->start();

MongoDB Adapter Usage

require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\MongoDBAdapter;

$adapter = new MongoDBAdapter(['dsn' => 'mongodb://127.0.0.1:27017', 'collation' => 'sessDbName.sessCollectionName']);

Session::createImmutable($adapter)
    ->start();

Credits

License

Copyright © 2022 MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固