Download the PHP package delight-im/cookie without Composer
On this page you can find all versions of the php package delight-im/cookie. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download delight-im/cookie
More information about delight-im/cookie
Files in delight-im/cookie
Package cookie
Short Description Modern cookie management for PHP
License MIT
Homepage https://github.com/delight-im/PHP-Cookie
Informations about the package cookie
PHP-Cookie
Modern cookie management for PHP
Requirements
- PHP 5.4.0+
Installation
-
Include the library via Composer [?]:
- Include the Composer autoloader:
Upgrading
Migrating from an earlier version of this project? See our upgrade guide for help.
Usage
Static method
This library provides a static method that is compatible to PHP’s built-in setcookie(...)
function but includes support for more recent features such as the SameSite
attribute:
Builder pattern
Instances of the Cookie
class let you build a cookie conveniently by setting individual properties. This class uses reasonable defaults that may differ from defaults of the setcookie
function.
The method calls can also be chained:
A cookie can later be deleted simply like this:
Note: For the deletion to work, the cookie must have the same settings as the cookie that was originally saved – except for its value, which doesn’t need to be set. So you should remember to pass appropriate values to setPath(...)
, setDomain(...)
, setHttpOnly(...)
and setSecureOnly(...)
again.
Reading cookies
-
Checking whether a cookie exists:
- Reading a cookie’s value (with optional default value):
Managing sessions
Using the Session
class, you can start and resume sessions in a way that is compatible to PHP’s built-in session_start()
function, while having access to the improved cookie handling from this library as well:
All three calls respect the settings from PHP’s session_set_cookie_params(...)
function and the configuration options session.name
, session.cookie_lifetime
, session.cookie_path
, session.cookie_domain
, session.cookie_secure
, session.cookie_httponly
and session.use_cookies
.
Likewise, replacements for
are available via
if you want protection against session fixation attacks that comes with improved cookie handling.
Additionally, access to the current internal session ID is provided via
as a replacement for
Reading and writing session data
-
Read a value from the session (with optional default value):
-
Write a value to the session:
-
Check whether a value exists in the session:
-
Remove a value from the session:
-
Read and then immediately remove a value from the session:
This is often useful for flash messages, e.g. in combination with the
has(...)
method.
Parsing cookies
Specifications
- RFC 2109
- RFC 6265
- Same-site Cookies (formerly 2016-06-20 and 2016-04-06)
- Amendment: Default to
Lax
and requiresecure
attribute forNone
(Note: There are incompatible clients)
- Amendment: Default to
Contributing
All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.
License
This project is licensed under the terms of the MIT License.