elephpant/cookie
Composer 安装命令:
composer require elephpant/cookie
包简介
A simple and effective way to work with Cookies
关键字:
README 文档
README
Installation
Composer (recommended)
Use Composer to install this library from Packagist:
elephpant/cookie
Run the following command from your project directory to add the dependency:
composer require elephpant/cookie "^2.0"
Alternatively, add the dependency directly to your composer.json file:
"require": { "elephpant/cookie": "^2.0" }
Usage
<?php use ElePHPant\Cookie\Cookie\Cookie; // default expiration: minutes // default encryption: there is no encryption $cookie = new Cookie(); // change expiration unit $options = [ 'expiration' => 'days', // seconds, minutes, hours, days, weeks, months, years ]; // set Base64 encryption $options = [ 'encryption' => \ElePHPant\Cookie\Strategies\Encryption\Base64EncryptionStrategy::class, ]; // set AES-256 encryption $options = [ 'encryption' => \ElePHPant\Cookie\Strategies\Encryption\AES256EncryptionStrategy::class, 'encrypt_key' => 'SET_YOUR_ENCRYPT_KEY_HERE', // required if using AES-256 ]; // other optional parameters $options['path'] = '/'; $options['domain'] = ''; $options['secure'] = false; $options['httponly'] = false; // SameSite $options['samesite'] = 'None'; // must be 'None', 'Lax' or 'Strict'. If none requires secure true $options['secure'] = true; // required if samesite is 'None' $cookie = new Cookie($options);
Create Cookie:
$str = 'john_doe'; $arr = ['name' => 'John Doe', 'email' => 'john@example.com', 'age' => 30,]; // name, value(s), expiration, ... $cookie::set('username', $str, 20); $cookie::set('user', $arr, 20);
Get Cookie(s):
echo $cookie::get('username'); // john_doe $arr = $cookie::get('user'); var_export($arr); // array ( 'name' => 'John Doe', 'email' => 'john@example.com', 'age' => 30, ) echo $arr['email']; // john@example.com $all = $cookie::get(); var_export($all); // array ( 'username' => 'john_doe', 'user' => array ( 'name' => 'John Doe', 'email' => 'john@example.com', 'age' => 30, ), ) var_export($_COOKIE); // array ( 'username' => '9sV1OIHc7taGoafeXWjl+gcrJFpIpg8Hkqe4fdGRygI=', 'user' => 'rLrCW9eBvoPijA+bSuIIrqbWccbYJqk2aPK5RGMwiLNpMZw2nYrrU7A2Zmuk3CGt0XiXlXpcQQv7h40M/6jbYslrlsvTJXm3mtG0nyiRDCg=', )
Create if Doesn't Exist:
$cookie::setDoesntHave('cookie_consent', true, 60);
Create if Doesn't Exist and Delete if it Exists:
$cookie::setDoesntHave('toggle_sidebar', true, 60, true);
Remove:
$cookie::destroy('user'); $cookie::destroy(); // all
Check if Exists:
if ($cookie::has('food')) { echo 'The cookie exists.'; } else { echo 'The cookie does not exist.'; }
Check if Exists by Value:
if ($cookie::has('username', $str)) { echo 'The cookie exists with the correct value.'; } else { echo 'The cookie does not exist or has a different value.'; } if ($cookie::has('user', $arr)) { echo 'The cookie exists with the correct value.'; } else { echo 'The cookie does not exist or has a different value.'; }
Contributing
No one ever has enough engineers, so we're very happy to accept contributions via Pull Requests. For details, see CONTRIBUTING
Credits
- Wilder Amorim (Developer)
- All Contributors (This Rock)
License
The MIT License (MIT). Please see License File for more information.
elephpant/cookie 适用场景与选型建议
elephpant/cookie 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 650 次下载、GitHub Stars 达 12, 最近一次更新时间为 2020 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cookie」 「ElePHPant」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elephpant/cookie 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elephpant/cookie 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elephpant/cookie 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
Popup component for Nette Framework
Cookie Consent is a lightweight JavaScript plugin for alerting users about the use of cookies on your website.
Breadcrumbs in an uncomplicated way. This component facilitates the way to create breadcrumbs for your website, to favor a more accessible navigation. It was designed to work very well with the Bootstrap Framework. Besides being very easy to use, it has very interesting possibilities, such as adding
A simple way to generate social share links.
A simple way to generate multiple favicons.
统计信息
- 总下载量: 650
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-14