Skip to content
PHP Ecosystem
Explore

Session

API reference › PSR bridge › http › Session

Keeps native session shutdown and flash aging bounded to the worker request lifecycle.

PropertyTypeDescriptionDefined by
$allFlashes read-onlyarrayFlash messages (key => message or key => [message1, message2]).yii\web\Session
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$cacheLimiterstringCurrent cache limiter.yii\web\Session
$cookieParamsarrayThe session cookie parameters.yii\web\Session
$count read-onlyintThe number of session variables.yii\web\Session
$flash write-onlystringThe key identifying the flash message.yii\web\Session
$flashParamstringThe name of the session variable that stores the flash message data. Default: '__flash'.yii\web\Session
$gCProbabilityfloatThe probability (percentage) that the GC (garbage collection) process is started on every session initialization.yii\web\Session
$handlerSessionHandlerInterface|arrayAn object implementing the SessionHandlerInterface or a configuration array. Default: null.yii\web\Session
$hasSessionIdboolWhether the current request has sent the session ID.yii\web\Session
$idstringThe current session ID.yii\web\Session
$isActive read-onlyboolWhether the session has started.yii\web\Session
$iterator read-onlyyii\web\SessionIteratorAn iterator for traversing the session variables.yii\web\Session
$namestringThe current session name.yii\web\Session
$savePathstringThe current session save path, defaults to ‘/tmp’.yii\web\Session
$timeoutintThe number of seconds after which data will be seen as ‘garbage’ and cleaned up.yii\web\Session
$useCookiesbool|nullThe value indicating whether cookies should be used to store session IDs.yii\web\Session
$useCustomStorage read-onlyboolWhether to use custom storage.yii\web\Session
$useStrictModeboolWhether strict mode is enabled or not.yii\web\Session
$useTransparentSessionIDboolWhether transparent sid support is enabled or not, defaults to false.yii\web\Session
$_forceRegenerateId protectedstring|nullHolds the session id in case useStrictMode is enabled and the session id needs to be regenerated Default: null.yii\web\Session
$_originalSessionModule protected staticstring|nullHolds 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.yii\web\Session
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
addFlash()Adds a flash message.yii\web\Session
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
close()Ends the current session and store session data.yii\web\Session
count()Returns the number of items in the session.yii\web\Session
destroy()Frees all session variables and destroys all data registered to a session.yii\web\Session
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
get()Returns the session variable value with the session variable name.yii\web\Session
getAllFlashes()Returns all flash messages.yii\web\Session
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getCacheLimiter()Returns current cache limiteryii\web\Session
getCookieParams()yii\web\Session
getCount()Returns the number of items in the session.yii\web\Session
getFlash()Returns a flash message.yii\web\Session
getGCProbability()yii\web\Session
getHasSessionId()Returns a value indicating whether the current request has sent the session ID.yii\web\Session
getId()Gets the session ID.yii\web\Session
getIsActive()yii\web\Session
getIterator()Returns an iterator for traversing the session variables.yii\web\Session
getName()Gets the name of the current session.yii\web\Session
getSavePath()Gets the current session save path.yii\web\Session
getTimeout()yii\web\Session
getUseCookies()Returns the value indicating whether cookies should be used to store session IDs.yii\web\Session
getUseCustomStorage()Returns a value indicating whether to use custom session storage.yii\web\Session
getUseStrictMode()yii\web\Session
getUseTransparentSessionID()yii\web\Session
has()yii\web\Session
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasFlash()Returns a value indicating whether there are flash messages associated with the specified key.yii\web\Session
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Replaces Yii’s per-instance shutdown callback with one weak process dispatcher.Session
off()Detaches an existing event handler from this component.yii\base\Component
offsetExists()This method is required by the interface ArrayAccess.yii\web\Session
offsetGet()This method is required by the interface ArrayAccess.yii\web\Session
offsetSet()This method is required by the interface ArrayAccess.yii\web\Session
offsetUnset()This method is required by the interface ArrayAccess.yii\web\Session
on()Attaches an event handler to an event.yii\base\Component
open()Starts the session.yii\web\Session
regenerateID()Updates the current session ID with a newly generated one.yii\web\Session
remove()Removes a session variable.yii\web\Session
removeAll()Removes all session variables.yii\web\Session
removeAllFlashes()Removes all flash messages.yii\web\Session
removeFlash()Removes a flash message.yii\web\Session
set()Adds a session variable.yii\web\Session
setCacheLimiter()Set cache limiteryii\web\Session
setCookieParams()Sets the session cookie parameters.yii\web\Session
setFlash()Sets a flash message.yii\web\Session
setGCProbability()yii\web\Session
setHasSessionId()Sets the value indicating whether the current request has sent the session ID.yii\web\Session
setId()Sets the session ID.yii\web\Session
setName()Sets the name for the current session.yii\web\Session
setSavePath()Sets the current session save path.yii\web\Session
setTimeout()yii\web\Session
setUseCookies()Sets the value indicating whether cookies should be used to store session IDs.yii\web\Session
setUseStrictMode()yii\web\Session
setUseTransparentSessionID()yii\web\Session
trigger()Triggers an event.yii\base\Component
freeze() protectedIf session is started it’s not possible to edit session ini settings. In PHP7.2+ it throws exception.yii\web\Session
registerSessionHandler() protectedRegisters session handler.yii\web\Session
unfreeze() protectedStarts session and restores data from temporary variableyii\web\Session
updateFlashCounters() protectedAges flash values once even when bootstrap and the action reopen the session.Session
public function init(): mixed

Replaces Yii’s per-instance shutdown callback with one weak process dispatcher.

Returns

mixed

protected function updateFlashCounters(): mixed

Ages flash values once even when bootstrap and the action reopen the session.

Returns

mixed