# 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](from-dotenv).

> **Custom storage**
>
> If you provide a [custom storage](plug) 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](/reference/sdk/php/api/storage/cookie-storage/emit).

## Signature

This method has the following signature:

```php
public static function emitCookies(?callable $emitter = null): void
```

## Example

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

```php
<?php
use Croct\Plug\Croct;

Croct::emitCookies();
```

## Parameters

The following list describes the supported parameters:

- `emitter`: `callable` (optional) (default: [setcookie](https://www.php.net/setcookie))

  The function used to send each cookie. It returns whether the cookie was sent.

  The function receives the following arguments:

  - `name`: `string`

    The name of the cookie.

  - `value`: `string`

    The value of the cookie.

  - `options`: `array`

    The cookie options.

    - `expires`: `int`

      The expiration time as a Unix timestamp in seconds, or `0` for a session cookie.

    - `path`: `string`

      The path on the server where the cookie is available.

    - `domain`: `string`

      The domain the cookie is available to.

    - `secure`: `boolean`

      Whether the cookie is sent only over HTTPS.

    - `httponly`: `boolean`

      Whether the cookie is inaccessible to JavaScript.

    - `samesite`: `string` (optional)

      The SameSite policy, one of `None`, `Lax`, or `Strict`.
