ph-7 / cookiesession
非常轻量级的库,可轻松简单地使用 PHP 7+ 管理会话和 Cookie
1.0.9
2017-07-03 01:34 UTC
Requires
- php: >=7.0.0
README
CookieSession 是一个非常轻量级的库,可轻松简单地使用 PHP 7+ 管理会话和 Cookie(无需花费时间配置和确保安全)。
Composer 安装
您可以通过使用 Composer 轻松将其添加到您的项目中。
$ composer require ph-7/cookiesession
然后,包含 Composer 的自动加载
require_once 'vendor/autoload.php';
手动安装
如果您不使用 Composer,您可以通过包含以下内容来不使用 Composer 进行安装
require 'src/autoloader.php';
会话使用方法
<?php use PH7\CookieSession\Session\Session; $oSession = new Session; $oSession->set('lang_pref', 'English'); // Create some sessions with an array $aData = [ 'my_session' => 'The value', 'another_session' => 'Another value', 'my_name' => 'Pierre-Henry' ]; // Add these sessions $oSession->set($aData); // Get session echo $oSession->get('lang_pref'); // Will display 'English' echo $oSession->get('another_session'); // Will display 'Another value' echo ($oSession->exists('my_name')) ? $oSession->get('my_name') : 'Well, well, we dont have a name in the session'; // Will display 'Pierre-Henry' $oSession->remove('my_name'); // Remove 'my_name' session echo $oSession->get('my_name'); // Will display nothing (empty string) as 'my_name' session has been removed
与 Cookie 的使用(非常相似)
<?php use PH7\CookieSession\Cookie\Cookie; $oCookie = new Cookie; $oCookie->set('mycookie', 'Amazing Value!'); // Create some cookies in array $aCookies = [ 'name' => 'Pierre-Henry', 'city' => 'Manchester', 'job' => 'Software Engineer' ]; $oCookie->set($aCookies); if ($oCookie->exists($aCookies)) { echo 'All the following cookies exist: ' . implode(', ', $aCookies); } echo $oCookie->get('name'); // Will display 'Pierre-Henry' echo $oCookie->get('mycookie'); // Will display 'Amazing Value!' $oCookie->remove($aCookies); // Remove all cookies echo $oCookie->get('name'); // Will display nothing (empty string)
要求
- PHP 7 或更高版本
作者
我是 Pierre-Henry Soria,一名 软件开发者,对许多事物充满热情,目前居住在英国曼彻斯特市
联系方式
您可以通过 pierrehenrysoria [AT] gmail {D0T} COM 或 phy [AT] hizup [D0T] UK 发送电子邮件
许可证
在 通用公共许可证 3 或更高版本下。