# CookieStorage

Learn how to persist the visitor session in cookies.

The cookie-based implementation of [`IdentityStore`](/reference/sdk/php/api/storage/identity-store), persisting the visitor session, such as the client ID and user token, in cookies.

It is the default session store the SDK creates [from the environment](/reference/sdk/php/api/core/croct/from-dotenv). You can also create one explicitly to customize the cookies, provide it [when you create the SDK](/reference/sdk/php/api/core/croct/plug), then [write the updated cookies](/reference/sdk/php/api/storage/cookie-storage/emit) before sending any output.

When you do not want to read or write cookies, such as in tests, use an [in-memory store](/reference/sdk/php/api/storage/in-memory-identity-store) instead. It exposes the same interface but keeps the client ID and user token in memory.

> **Looking for something specific?**
>
> Use the search bar at the top of the page or press `/` to quickly search through the documentation.

Use the summary below to quickly jump to a specific topic:

- [Constructor](/reference/sdk/php/api/storage/cookie-storage/construct): Learn how to initialize a cookie storage directly.
- [fromGlobals](/reference/sdk/php/api/storage/cookie-storage/from-globals): Learn how to create a storage from the PHP superglobals.
- [fromServerRequest](/reference/sdk/php/api/storage/cookie-storage/from-server-request): Learn how to create a storage from a PSR-7 server request.
- [fromArray](/reference/sdk/php/api/storage/cookie-storage/from-array): Learn how to create a storage from an array of cookies.
- [getResponseCookies](/reference/sdk/php/api/storage/cookie-storage/get-response-cookies): Learn how to get the session cookies to write to the response.
- [emit](/reference/sdk/php/api/storage/cookie-storage/emit): Learn how to write the session cookies to the response.
