Download the PHP package setono/client without Composer
On this page you can find all versions of the php package setono/client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download setono/client
More information about setono/client
Files in setono/client
Package client
Short Description PHP abstraction for identifying a browser client
License MIT
Informations about the package client
PHP abstraction for identifying a browser client
This library provides a small, framework-agnostic value object for identifying a browser client: a stable id
together with arbitrary, optionally expiring metadata. A companion Cookie class serializes that id — along with a
format version and "first/last seen" timestamps — to and from a cookie value, so the same visitor can be recognized
across requests.
Installation
When you don't supply an id yourself, the library generates a UUIDv7. To use that, install one of the supported UUID
libraries (if both are installed, symfony/uid is preferred):
Usage
The client
Metadata
Metadata is a string => mixed bag. It implements ArrayAccess, Countable and IteratorAggregate, so you can
use it like an array:
Expiring entries
Pass a TTL (in seconds) as the third argument to set(). Expired entries are pruned lazily: they are no longer
returned by get()/has() and are excluded from iteration and count().
Persisting and restoring
Metadata::toArray() returns everything needed to rebuild the object — including the expiry bookkeeping — so you can
store it (in a database, cache, session, ...) and reconstruct the client later with the timestamps intact:
Client and Metadata are also JsonSerializable:
Storing the id in a cookie
The Cookie class converts a client id to and from a cookie value. The value also carries a format version and the
timestamps for when the client was first and last seen. The library only produces and parses the string — reading the
request cookie and writing it to the response is left to your HTTP layer.