# MultiFieldSession

> MultiFieldSession is the base class for session storage implementations with multi-field data storage support.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › MultiFieldSession

| abstract class | `yii\web\MultiFieldSession` |
| --- | --- |
| Extends | [`Session`](/docs/api/yii/web/session/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md), [`IteratorAggregate`](https://www.php.net/manual/en/class.iteratoraggregate.php), [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php), [`Countable`](https://www.php.net/manual/en/class.countable.php) |
| Since | 2.0.6 |
| Source | [`framework/web/MultiFieldSession.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/MultiFieldSession.php#L31) |

1 subclass:

- [`DbSession`](/docs/api/yii/web/dbsession/index.md)

MultiFieldSession is the base class for session storage implementations with multi-field data storage support.

With multi-field data storage, session data can be split between several fields in the storage record.
Using such a storage allows saving particular session data into separated field, which then can be used
to manipulate sessions in the way plain PHP does not allow.

For example the ID of the authenticated user can be saved as separated column in the MySQL 'session' table,
which allows to query all active sessions for a particular user or terminate them at will.

Customizing of the session writing is performed via [`$writeCallback`](/docs/api/yii/web/multifieldsession/index.md#property-writeCallback), reading via [`$readCallback`](/docs/api/yii/web/multifieldsession/index.md#property-readCallback).

While extending this class you should use [`composeFields()`](/docs/api/yii/web/multifieldsession/index.md#method-composeFields) method - while writing the session data into the storage and
[`extractData()`](/docs/api/yii/web/multifieldsession/index.md#method-extractData) - while reading session data from the storage.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-allFlashes"></span>[`$allFlashes`](/docs/api/yii/web/session/index.md#property-allFlashes) read-only | `array` | Flash messages (key => message or key => [message1, message2]). | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-cacheLimiter"></span>[`$cacheLimiter`](/docs/api/yii/web/session/index.md#property-cacheLimiter) | `string` | Current cache limiter. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-cookieParams"></span>[`$cookieParams`](/docs/api/yii/web/session/index.md#property-cookieParams) | `array` | The session cookie parameters. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-count"></span>[`$count`](/docs/api/yii/web/session/index.md#property-count) read-only | `int` | The number of session variables. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-flash"></span>[`$flash`](/docs/api/yii/web/session/index.md#property-flash) write-only | `string` | The key identifying the flash message. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-flashParam"></span>[`$flashParam`](/docs/api/yii/web/session/index.md#property-flashParam) | `string` | The name of the session variable that stores the flash message data. Default: `'__flash'`. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-gCProbability"></span>[`$gCProbability`](/docs/api/yii/web/session/index.md#property-gCProbability) | `float` | The probability (percentage) that the GC (garbage collection) process is started on every session initialization. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-handler"></span>[`$handler`](/docs/api/yii/web/session/index.md#property-handler) | [`SessionHandlerInterface`](https://www.php.net/manual/en/class.sessionhandlerinterface.php)`\|array` | An object implementing the SessionHandlerInterface or a configuration array. Default: `null`. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-hasSessionId"></span>[`$hasSessionId`](/docs/api/yii/web/session/index.md#property-hasSessionId) | `bool` | Whether the current request has sent the session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-id"></span>[`$id`](/docs/api/yii/web/session/index.md#property-id) | `string` | The current session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-isActive"></span>[`$isActive`](/docs/api/yii/web/session/index.md#property-isActive) read-only | `bool` | Whether the session has started. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-iterator"></span>[`$iterator`](/docs/api/yii/web/session/index.md#property-iterator) read-only | [`SessionIterator`](/docs/api/yii/web/sessioniterator/index.md) | An iterator for traversing the session variables. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-name"></span>[`$name`](/docs/api/yii/web/session/index.md#property-name) | `string` | The current session name. | [`Session`](/docs/api/yii/web/session/index.md) |
| [`$readCallback`](#property-readCallback) | `callable` | A callback that will be called during session data reading. Default: `null`. | `MultiFieldSession` |
| <span id="property-savePath"></span>[`$savePath`](/docs/api/yii/web/session/index.md#property-savePath) | `string` | The current session save path, defaults to '/tmp'. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-timeout"></span>[`$timeout`](/docs/api/yii/web/session/index.md#property-timeout) | `int` | The number of seconds after which data will be seen as 'garbage' and cleaned up. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-useCookies"></span>[`$useCookies`](/docs/api/yii/web/session/index.md#property-useCookies) | `bool\|null` | The value indicating whether cookies should be used to store session IDs. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-useCustomStorage"></span>`$useCustomStorage` read-only | `bool` | Whether to use custom storage. | `MultiFieldSession` |
| <span id="property-useStrictMode"></span>[`$useStrictMode`](/docs/api/yii/web/session/index.md#property-useStrictMode) | `bool` | Whether strict mode is enabled or not. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-useTransparentSessionID"></span>[`$useTransparentSessionID`](/docs/api/yii/web/session/index.md#property-useTransparentSessionID) | `bool` | Whether transparent sid support is enabled or not, defaults to false. | [`Session`](/docs/api/yii/web/session/index.md) |
| [`$writeCallback`](#property-writeCallback) | `callable\|null` | A callback that will be called during session data writing. Default: `null`. | `MultiFieldSession` |
| <span id="property-_forceRegenerateId"></span>[`$_forceRegenerateId`](/docs/api/yii/web/session/index.md#property-_forceRegenerateId) protected | `string\|null` | Holds the session id in case useStrictMode is enabled and the session id needs to be regenerated Default: `null`. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="property-_originalSessionModule"></span>[`$_originalSessionModule`](/docs/api/yii/web/session/index.md#property-_originalSessionModule) protected static | `string\|null` | Holds the original session module (before a custom handler is registered) so that it can be restored when a Session component without custom handler is used after one that has. Default: `null`. | [`Session`](/docs/api/yii/web/session/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-addFlash"></span>[`addFlash()`](/docs/api/yii/web/session/index.md#method-addFlash) | Adds a flash message. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-close"></span>[`close()`](/docs/api/yii/web/session/index.md#method-close) | Ends the current session and store session data. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-count"></span>[`count()`](/docs/api/yii/web/session/index.md#method-count) | Returns the number of items in the session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-destroy"></span>[`destroy()`](/docs/api/yii/web/session/index.md#method-destroy) | Frees all session variables and destroys all data registered to a session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-get"></span>[`get()`](/docs/api/yii/web/session/index.md#method-get) | Returns the session variable value with the session variable name. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getAllFlashes"></span>[`getAllFlashes()`](/docs/api/yii/web/session/index.md#method-getAllFlashes) | Returns all flash messages. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getCacheLimiter"></span>[`getCacheLimiter()`](/docs/api/yii/web/session/index.md#method-getCacheLimiter) | Returns current cache limiter | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getCookieParams"></span>[`getCookieParams()`](/docs/api/yii/web/session/index.md#method-getCookieParams) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getCount"></span>[`getCount()`](/docs/api/yii/web/session/index.md#method-getCount) | Returns the number of items in the session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getFlash"></span>[`getFlash()`](/docs/api/yii/web/session/index.md#method-getFlash) | Returns a flash message. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getGCProbability"></span>[`getGCProbability()`](/docs/api/yii/web/session/index.md#method-getGCProbability) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getHasSessionId"></span>[`getHasSessionId()`](/docs/api/yii/web/session/index.md#method-getHasSessionId) | Returns a value indicating whether the current request has sent the session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getId"></span>[`getId()`](/docs/api/yii/web/session/index.md#method-getId) | Gets the session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getIsActive"></span>[`getIsActive()`](/docs/api/yii/web/session/index.md#method-getIsActive) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getIterator"></span>[`getIterator()`](/docs/api/yii/web/session/index.md#method-getIterator) | Returns an iterator for traversing the session variables. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getName"></span>[`getName()`](/docs/api/yii/web/session/index.md#method-getName) | Gets the name of the current session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getSavePath"></span>[`getSavePath()`](/docs/api/yii/web/session/index.md#method-getSavePath) | Gets the current session save path. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getTimeout"></span>[`getTimeout()`](/docs/api/yii/web/session/index.md#method-getTimeout) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getUseCookies"></span>[`getUseCookies()`](/docs/api/yii/web/session/index.md#method-getUseCookies) | Returns the value indicating whether cookies should be used to store session IDs. | [`Session`](/docs/api/yii/web/session/index.md) |
| [`getUseCustomStorage()`](#method-getUseCustomStorage) | Returns a value indicating whether to use custom session storage. | `MultiFieldSession` |
| <span id="method-getUseStrictMode"></span>[`getUseStrictMode()`](/docs/api/yii/web/session/index.md#method-getUseStrictMode) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-getUseTransparentSessionID"></span>[`getUseTransparentSessionID()`](/docs/api/yii/web/session/index.md#method-getUseTransparentSessionID) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-has"></span>[`has()`](/docs/api/yii/web/session/index.md#method-has) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasFlash"></span>[`hasFlash()`](/docs/api/yii/web/session/index.md#method-hasFlash) | Returns a value indicating whether there are flash messages associated with the specified key. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/web/session/index.md#method-init) | Initializes the application component. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-offsetExists"></span>[`offsetExists()`](/docs/api/yii/web/session/index.md#method-offsetExists) | This method is required by the interface [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php). | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-offsetGet"></span>[`offsetGet()`](/docs/api/yii/web/session/index.md#method-offsetGet) | This method is required by the interface [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php). | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-offsetSet"></span>[`offsetSet()`](/docs/api/yii/web/session/index.md#method-offsetSet) | This method is required by the interface [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php). | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-offsetUnset"></span>[`offsetUnset()`](/docs/api/yii/web/session/index.md#method-offsetUnset) | This method is required by the interface [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php). | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-open"></span>[`open()`](/docs/api/yii/web/session/index.md#method-open) | Starts the session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-regenerateID"></span>[`regenerateID()`](/docs/api/yii/web/session/index.md#method-regenerateID) | Updates the current session ID with a newly generated one. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-remove"></span>[`remove()`](/docs/api/yii/web/session/index.md#method-remove) | Removes a session variable. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-removeAll"></span>[`removeAll()`](/docs/api/yii/web/session/index.md#method-removeAll) | Removes all session variables. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-removeAllFlashes"></span>[`removeAllFlashes()`](/docs/api/yii/web/session/index.md#method-removeAllFlashes) | Removes all flash messages. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-removeFlash"></span>[`removeFlash()`](/docs/api/yii/web/session/index.md#method-removeFlash) | Removes a flash message. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-set"></span>[`set()`](/docs/api/yii/web/session/index.md#method-set) | Adds a session variable. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setCacheLimiter"></span>[`setCacheLimiter()`](/docs/api/yii/web/session/index.md#method-setCacheLimiter) | Set cache limiter | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setCookieParams"></span>[`setCookieParams()`](/docs/api/yii/web/session/index.md#method-setCookieParams) | Sets the session cookie parameters. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setFlash"></span>[`setFlash()`](/docs/api/yii/web/session/index.md#method-setFlash) | Sets a flash message. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setGCProbability"></span>[`setGCProbability()`](/docs/api/yii/web/session/index.md#method-setGCProbability) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setHasSessionId"></span>[`setHasSessionId()`](/docs/api/yii/web/session/index.md#method-setHasSessionId) | Sets the value indicating whether the current request has sent the session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setId"></span>[`setId()`](/docs/api/yii/web/session/index.md#method-setId) | Sets the session ID. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setName"></span>[`setName()`](/docs/api/yii/web/session/index.md#method-setName) | Sets the name for the current session. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setSavePath"></span>[`setSavePath()`](/docs/api/yii/web/session/index.md#method-setSavePath) | Sets the current session save path. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setTimeout"></span>[`setTimeout()`](/docs/api/yii/web/session/index.md#method-setTimeout) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setUseCookies"></span>[`setUseCookies()`](/docs/api/yii/web/session/index.md#method-setUseCookies) | Sets the value indicating whether cookies should be used to store session IDs. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setUseStrictMode"></span>[`setUseStrictMode()`](/docs/api/yii/web/session/index.md#method-setUseStrictMode) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-setUseTransparentSessionID"></span>[`setUseTransparentSessionID()`](/docs/api/yii/web/session/index.md#method-setUseTransparentSessionID) |  | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`composeFields()`](#method-composeFields) protected | Composes storage field set for session writing. | `MultiFieldSession` |
| [`extractData()`](#method-extractData) protected | Extracts session data from storage field set. | `MultiFieldSession` |
| <span id="method-freeze"></span>[`freeze()`](/docs/api/yii/web/session/index.md#method-freeze) protected | If session is started it's not possible to edit session ini settings. In PHP7.2+ it throws exception. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-registerSessionHandler"></span>[`registerSessionHandler()`](/docs/api/yii/web/session/index.md#method-registerSessionHandler) protected | Registers session handler. | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-unfreeze"></span>[`unfreeze()`](/docs/api/yii/web/session/index.md#method-unfreeze) protected | Starts session and restores data from temporary variable | [`Session`](/docs/api/yii/web/session/index.md) |
| <span id="method-updateFlashCounters"></span>[`updateFlashCounters()`](/docs/api/yii/web/session/index.md#method-updateFlashCounters) protected | Updates the counters for flash messages and removes outdated flash messages. | [`Session`](/docs/api/yii/web/session/index.md) |

## Property details

### $readCallback <span id="property-readCallback"></span>

```php
public callable $readCallback = null
```

A callback that will be called during session data reading.

The signature of the callback should be as follows:

```
function ($fields)
```

where `$fields` is the storage field set for read session and `$session` is this session instance.
If callback returns an array, it will be merged into the session data.

For example:

```
function ($fields) {
    return [
        'expireDate' => Yii::$app->formatter->asDate($fields['expire']),
    ];
}
```

### $writeCallback <span id="property-writeCallback"></span>

```php
public callable|null $writeCallback = null
```

A callback that will be called during session data writing.

The signature of the callback should be as follows:

```
function ($session)
```

where `$session` is this session instance, this variable can be used to retrieve session data.
Callback should return the actual fields set, which should be saved into the session storage.

For example:

```
function ($session) {
    return [
        'user_id' => Yii::$app->user->id,
        'ip' => $_SERVER['REMOTE_ADDR'],
        'is_trusted' => $session->get('is_trusted', false),
    ];
}
```

## Method details

### getUseCustomStorage() <span id="method-getUseCustomStorage"></span>

```php
public function getUseCustomStorage(): bool
```

Returns a value indicating whether to use custom session storage.

This method overrides the parent implementation and always returns true.

**Returns**

`bool`: Whether to use custom storage.

### composeFields() <span id="method-composeFields"></span>

```php
protected function composeFields(string|null $id = null, string|null $data = null): array
```

Composes storage field set for session writing.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$id` | `string\|null` | Optional session id |
| `$data` | `string\|null` | Optional session data |

**Returns**

`array`: Storage fields

### extractData() <span id="method-extractData"></span>

```php
protected function extractData(array $fields): string
```

Extracts session data from storage field set.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$fields` | `array` | Storage fields. |

**Returns**

`string`: Session data.