phpgt / cookie
面向对象风格的cookie处理程序。
v1.0.2
2019-07-17 20:11 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: 8.*
This package is auto-updated.
Last update: 2024-09-10 17:02:05 UTC
README
此库是一个简单的面向对象替代品,用于替代可以通过相同关联数组样式代码读取的$_COOKIE
超级全局变量。`Cookie`类以不可变对象的形式表示cookie数据,这意味着请求/响应cookie的状态不能被代码的未知区域意外更改。
示例用法
// 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!
未涵盖的内容是什么?
此库不涉及cookie加密。要跨HTTP请求存储敏感信息,请使用会话变量。为了确保cookie不能被JavaScript读取,请使用安全的仅HTTP cookie。