承接 natilosir/cookie 相关项目开发

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

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

natilosir/cookie

最新稳定版本:1.0.1

Composer 安装命令:

composer require natilosir/cookie

包简介

A simple library for creating and managing cookies in PHP

README 文档

README

Overview

The PHP Cookie Manager is a simple and effective class for managing cookies in PHP applications. This class provides static methods to set, get, delete, and list cookies easily, allowing for straightforward cookie management without the need for instantiation.

Installation

To use the PHP Cookie Manager in your project, simply include the Cookie.php file in your project. You can also install it via Composer.

composer require natilosir/cookie

Usage

Setting a Cookie

To set a cookie, use the set method. You can specify the cookie name, value, and expiration time in days.

use natilosir\cookie\Cookie;

// Set a cookie
Cookie::set('username', 'JohnDoe', 7); // Expires in 7 days

Getting a Cookie

To retrieve the value of a cookie, use the get method.

// Get the cookie value
$username = Cookie::get('username');
echo 'Username: ' . $username; // Outputs: Username: JohnDoe

Deleting a Cookie

To delete a cookie, use the delete method.

// Delete the cookie
Cookie::delete('username');

Listing All Cookies

To list all cookies available in the current session, use the list method.

// List all cookies
$allCookies = Cookie::list();
print_r($allCookies); // Outputs all cookies

Methods

set($name, $value, $days = 0)

Sets a cookie with the specified name and value. If $days is greater than 0, the cookie will expire after the specified number of days.

get($name)

Retrieves the value of the cookie with the specified name. Returns null if the cookie does not exist.

delete($name)

Deletes the cookie with the specified name by setting its expiration date to a time in the past.

list()

Returns an associative array of all cookies currently available in the $_COOKIE superglobal.

Example

Here is a complete example demonstrating how to use the PHP Cookie Manager:

use natilosir\cookie\Cookie;

// Set a cookie
Cookie::set('username', 'JohnDoe', 7);

// Get the cookie value
$username = Cookie::get('username');
echo 'Username: ' . $username; // Outputs: Username: JohnDoe

// Delete the cookie
Cookie::delete('username');

// List all cookies
$allCookies = Cookie::list();
print_r($allCookies); // Outputs all cookies

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-23