定制 codezero/cookie 二次开发

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

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

codezero/cookie

最新稳定版本:2.0.0

Composer 安装命令:

composer require codezero/cookie

包简介

Your friendly, furry cookie monster. Get and set cookies with ease.

README 文档

README

GitHub release License Build Status Code Coverage Scrutinizer Code Quality Total Downloads

ko-fi

Your friendly, furry cookie monster!

Get and set cookies in vanilla PHP with ease. A Laravel implementation is included, but this has no real advantages if you only use Laravel.

CAUTION! Never store sensitive data in a cookie!

Installation

Install this package through Composer:

composer require codezero/cookie

Vanilla PHP Implementation

Autoload the vendor classes:

require_once 'vendor/autoload.php'; // Path may vary

And then use the VanillaCookie implementation:

$cookie = new \CodeZero\Cookie\VanillaCookie();

If you want your cookies to be encrypted, pass an instance of codezero/encrypter to the Cookie class. You will also need to provide it with an encryption key that is needed to decrypt the cookie later on.

$key = 'my secret app key'; $encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key); $cookie = new \CodeZero\Cookie\VanillaCookie($encrypter);

TIP: Laravel automagically encrypts cookies by default!

Laravel 5 Implementation

You can "make" (or inject) a Cookie instance anywhere in your app:

$cookie = \App::make('CodeZero\Cookie\Cookie');

TIP: Laravel's IoC container will automatically provide the Laravel specific Cookie implementation. This will use Laravel's Cookie goodness behind the scenes!

Usage

Get a cookie

This will return null if the cookie doesn't exist or is expired.

$cookieValue = $cookie->get('cookieName');

Store a cookie for a limited time

If you don't specify $minutesValid, a default of 60 minutes will be used.

$minutesValid = 120; $cookie->store('cookieName', 'cookieValue', $minutesValid);

Store a cookie forever

5 years feels like forever... ;)

$cookie->forever('cookieName', 'cookieValue');

Delete a cookie

If the cookie doesn't exist, nothing will happen...

$cookie->delete('cookieName');

Check if a cookie exists

You can check if a cookie exists. However, keep in mind that a cookie will not be available immediately. It will be on the next page load.

if ($cookie->exists('cookieName')) { // The cookie exists! }

Testing

$ composer run test

Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固