emit
Learn how to write the session cookies to the response.
This method writes the session cookies, such as the client ID and user token, as Set-Cookie headers.
Call it before sending any output. Use getResponseCookies instead when integrating with a framework that manages the response.
Signature
This method has the following signature:
public function emit(?callable $emitter = null): voidExample
Here is a basic example of how to use this method:
<?phpuse Croct\Plug\CookieStorage;
$storage = CookieStorage::fromGlobals();$storage->emit();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