fromGlobals

Learn how to create a storage from the PHP superglobals.

This static method creates a storage from the PHP superglobals, reading the cookies from the current request.

Use it in plain PHP scripts where the request cookies are available through the $_COOKIE superglobal.

Signature

This method has the following signature:

public static function fromGlobals(?CookieConfiguration $configuration = null, ?int $now = null): self

This method returns a new instance initialized with the client ID and user token read from the current request’s cookies.

Example

Here is a basic example of how to use this method:

<?phpuse Croct\Plug\CookieStorage;
$storage = CookieStorage::fromGlobals();

Parameters

The following list describes the supported parameters:

configuration(optional)

The cookie configuration, such as the cookie names and domain. The default is null, which uses the standard configuration.

Default:null
now(optional)
integer

The current time as a Unix timestamp in seconds, used to compute the cookie expiration. The default is null, which uses the current time.

Default:null