phpgt/cookie
最新稳定版本:v1.0.3
Composer 安装命令:
composer require phpgt/cookie
包简介
Object oriented cookie handler.
README 文档
README
This library is an object oriented alternative to the $_COOKIE superglobal that can be read using the same associative array style code. The Cookie class represents cookie data in immutable objects, meaning that the state of the request/response cookies cannot be accidentally changed by undisclosed areas of code.
Example usage
// Create a replacement for $_COOKIE. $cookie = new Gt\Cookie\CookieHandler($_COOKIE); // Access values as normal. $value = $cookie["firstVisit"]; if(isset($cookie["firstVisit"])) { // Cookie "firstVisit" exists. } if($cookie->has("firstVisit")) { // Cookie "firstVisit" exists. } else { // Create a new cookie that expires in ten days. $now = new DateTime(); $expire = new DateTime("+10 days"); $cookie->set("firstVisit", $now, $expire); } // Now you can unset the superglobal!
What's not covered?
This library does not touch on encrypting cookies. To store sensitive information across HTTP requests, use a session variable. To ensure cookies can't be read by JavaScript, use a secure HTTP-only cookie.
Proudly sponsored by
统计信息
- 总下载量: 3.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-15