Download the PHP package initphp/cookies without Composer

On this page you can find all versions of the php package initphp/cookies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cookies

InitPHP Cookies

A signed, tamper-evident cookie manager for PHP. Values are stored in a single browser cookie whose payload is authenticated with an HMAC-SHA256 signature, so a client cannot read-tamper its way into forging cookie data. Each value can carry its own time-to-live.

Designed & Maintained with Tan CI Latest Stable Version

Features

Requirements

Installation

Quick start

On the next request:

Important: like PHP's native setcookie(), send() writes HTTP headers, so it must run before any output. Call it explicitly at the end of your request handling. The destructor calls send() as a safety-net, but relying on it is discouraged.

How it works

The manager keeps an in-memory working copy of your values. Mutating methods change only that copy; nothing reaches the browser until send() is called. On send() the working copy is:

  1. stripped of expired entries,
  2. serialize()-d and base64-encoded into a payload,
  3. signed: signature = hash_hmac('sha256', payload, salt),
  4. written as the cookie value "{payload}.{signature}".

On construction the incoming cookie is verified before anything is deserialized: the signature is recomputed and compared with hash_equals(). If it does not match (tampering, a different salt, a truncated value), the payload is discarded and a clean cookie is re-issued. Because deserialization happens only after that check and with allowed_classes => false, a malicious cookie cannot trigger PHP object injection.

Configuration

The third constructor argument overrides the default cookie attributes. Only the keys you pass are changed; the rest keep their defaults.

Option Type Default Description
ttl int 2592000 Lifetime of the browser cookie in seconds. Per-value TTLs are separate.
path string '/' Cookie path.
domain string\|null null Cookie domain. Omitted from the header when null.
secure bool false Send only over HTTPS.
httponly bool true Hide the cookie from JavaScript.
samesite string 'Strict' Strict, Lax or None. None automatically forces secure => true.

ttl vs. per-key TTL

API

Method Description
has Whether a non-expired value exists. An expired value is removed and reported as absent.
get The value for $key, or $default when absent/expired. Scalar types are preserved.
pull Like get, but removes the value afterwards (read-once).
set Stage a single value. $ttl is seconds from now, or null for no per-key expiry.
setArray Stage several values from an associative array sharing one TTL.
push Like set, but returns the staged value.
all All non-expired values as a key => value map.
remove Stage removal of one or more keys.
send Write the staged state to the browser. No-op when nothing changed.
flush Empty all values; the next send() writes an empty (still signed) cookie.
destroy Immediately expire and clear the transport cookie in the browser.

Allowed value types are string, bool, int, float and numeric strings. Anything else throws InitPHP\Cookies\Exception\CookieInvalidArgumentException.

Documentation

Full developer documentation lives in docs/: getting started, usage guides, the configuration reference, the security model, the API reference and practical recipes.

Upgrading from 1.x

Version 2.0 is a security and correctness release with intentional breaking changes:

Testing

Credits

License

Released under the MIT License. Copyright © 2022 InitPHP.


All versions of cookies with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
initphp/parameterbag Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package initphp/cookies contains the following files

Loading the files please wait ...