emitCookies
Learn how to write the session cookies to the response.
This static method writes the visitor session cookies, such as the client ID and user token, as Set-Cookie headers.
Call it before sending any output. It emits the cookies of the default session store the SDK creates from the environment.
If you provide a custom storage to the SDK, do not use this method. It writes only the default global cookie store. Handle the session through your own storage instead, for example by writing its cookies to the response.
Signature
This method has the following signature:
public static function emitCookies(?callable $emitter = null): voidExample
Here is a basic example of how to use this method:
<?phpuse Croct\Plug\Croct;
Croct::emitCookies();Parameters
The following list describes the supported parameters:
- emitter(optional)callable
The function used to send each cookie. It returns whether the cookie was sent.
The function receives the following arguments:
- namestring
The name of the cookie.
- valuestring
The value of the cookie.
- optionsarray
The cookie options.
- expiresint
The expiration time as a Unix timestamp in seconds, or 0 for a session cookie.
- pathstring
The path on the server where the cookie is available.
- domainstring
The domain the cookie is available to.
- secureboolean
Whether the cookie is sent only over HTTPS.
- httponlyboolean
Whether the cookie is inaccessible to JavaScript.
- samesite(optional)string
The SameSite policy, one of None, Lax, or Strict.
- expires
Default:setcookie- name