SessionInterface
in
Expected behavior of a session container used with CodeIgniter.
Table of Contents
Methods
- destroy() : mixed
- Destroys the current session.
- get() : array<string|int, mixed>|bool|float|int|object|string|null
- Get user data that has been set in the session.
- getFlashdata() : array<string|int, mixed>|null
- Retrieve one or more items of flash data from the session.
- getFlashKeys() : array<string|int, mixed>
- Retrieve all of the keys for session data marked as flashdata.
- getTempdata() : array<string|int, mixed>|bool|float|int|object|string|null
- Returns either a single piece of tempdata, or all temp data currently in the session.
- getTempKeys() : array<string|int, mixed>
- Retrieve the keys of all session data that have been marked as temporary data.
- has() : bool
- Returns whether an index exists in the session array.
- keepFlashdata() : mixed
- Keeps a single piece of flash data alive for one more request.
- markAsFlashdata() : false
- Mark a session property or properties as flashdata.
- markAsTempdata() : bool
- Mark one of more pieces of data as being temporary, meaning that it has a set lifespan within the session.
- regenerate() : mixed
- Regenerates the session ID.
- remove() : mixed
- Remove one or more session properties.
- removeTempdata() : mixed
- Removes a single piece of temporary data from the session.
- set() : mixed
- Sets user data into the session.
- setFlashdata() : mixed
- Sets data into the session that will only last for a single request.
- setTempdata() : mixed
- Sets new data into the session, and marks it as temporary data with a set lifespan.
- unmarkFlashdata() : mixed
- Unmark data in the session as flashdata.
- unmarkTempdata() : mixed
- Unmarks temporary data in the session, effectively removing its lifespan and allowing it to live as long as the session does.
Methods
destroy()
Destroys the current session.
public
destroy() : mixed
get()
Get user data that has been set in the session.
public
get([non-empty-string|null $key = null ]) : array<string|int, mixed>|bool|float|int|object|string|null
If the property exists as "normal", returns it. Otherwise, returns an array of any temp or flash data values with the property key.
Replaces the legacy method $session->userdata();
Parameters
- $key : non-empty-string|null = null
-
Identifier of the session property to retrieve
Return values
array<string|int, mixed>|bool|float|int|object|string|null —The property value(s)
getFlashdata()
Retrieve one or more items of flash data from the session.
public
getFlashdata([string $key = null ]) : array<string|int, mixed>|null
If the item key is null, return all flashdata.
Parameters
- $key : string = null
-
Property identifier
Return values
array<string|int, mixed>|null —The requested property value, or an associative array of them
getFlashKeys()
Retrieve all of the keys for session data marked as flashdata.
public
getFlashKeys() : array<string|int, mixed>
Return values
array<string|int, mixed> —The property names of all flashdata
getTempdata()
Returns either a single piece of tempdata, or all temp data currently in the session.
public
getTempdata([string $key = null ]) : array<string|int, mixed>|bool|float|int|object|string|null
Parameters
- $key : string = null
-
Session data key
Return values
array<string|int, mixed>|bool|float|int|object|string|null —Session data value or null if not found.
getTempKeys()
Retrieve the keys of all session data that have been marked as temporary data.
public
getTempKeys() : array<string|int, mixed>
Return values
array<string|int, mixed>has()
Returns whether an index exists in the session array.
public
has(string $key) : bool
Parameters
- $key : string
-
Identifier of the session property we are interested in.
Return values
boolkeepFlashdata()
Keeps a single piece of flash data alive for one more request.
public
keepFlashdata(array<string|int, mixed>|string $key) : mixed
Parameters
- $key : array<string|int, mixed>|string
-
Property identifier or array of them
markAsFlashdata()
Mark a session property or properties as flashdata.
public
markAsFlashdata(array<string|int, mixed>|string $key) : false
Parameters
- $key : array<string|int, mixed>|string
-
Property identifier or array of them
Return values
false —if any of the properties are not already set
markAsTempdata()
Mark one of more pieces of data as being temporary, meaning that it has a set lifespan within the session.
public
markAsTempdata(array<string|int, mixed>|string $key[, int $ttl = 300 ]) : bool
Parameters
- $key : array<string|int, mixed>|string
-
Property identifier or array of them
- $ttl : int = 300
-
Time to live, in seconds
Return values
bool —False if any of the properties were not set
regenerate()
Regenerates the session ID.
public
regenerate([bool $destroy = false ]) : mixed
Parameters
- $destroy : bool = false
-
Should old session data be destroyed?
remove()
Remove one or more session properties.
public
remove(array<string|int, mixed>|string $key) : mixed
If $key is an array, it is interpreted as an array of string property identifiers to remove. Otherwise, it is interpreted as the identifier of a specific session property to remove.
Parameters
- $key : array<string|int, mixed>|string
-
Identifier of the session property or properties to remove.
removeTempdata()
Removes a single piece of temporary data from the session.
public
removeTempdata(string $key) : mixed
Parameters
- $key : string
-
Session data key
set()
Sets user data into the session.
public
set(array<string|int, mixed>|string $data[, array<string|int, mixed>|bool|float|int|object|string|null $value = null ]) : mixed
If $data is a string, then it is interpreted as a session property key, and $value is expected to be non-null.
If $data is an array, it is expected to be an array of key/value pairs to be set as session properties.
Parameters
- $data : array<string|int, mixed>|string
-
Property name or associative array of properties
- $value : array<string|int, mixed>|bool|float|int|object|string|null = null
-
Property value if single key provided
setFlashdata()
Sets data into the session that will only last for a single request.
public
setFlashdata(array<string|int, mixed>|string $data[, array<string|int, mixed>|string $value = null ]) : mixed
Perfect for use with single-use status update messages.
If $data is an array, it is interpreted as an associative array of key/value pairs for flashdata properties. Otherwise, it is interpreted as the identifier of a specific flashdata property, with $value containing the property value.
Parameters
- $data : array<string|int, mixed>|string
-
Property identifier or associative array of properties
- $value : array<string|int, mixed>|string = null
-
Property value if $data is a scalar
setTempdata()
Sets new data into the session, and marks it as temporary data with a set lifespan.
public
setTempdata(array<string|int, mixed>|string $data[, array<string|int, mixed>|bool|float|int|object|string|null $value = null ][, int $ttl = 300 ]) : mixed
Parameters
- $data : array<string|int, mixed>|string
-
Session data key or associative array of items
- $value : array<string|int, mixed>|bool|float|int|object|string|null = null
-
Value to store
- $ttl : int = 300
-
Time-to-live in seconds
unmarkFlashdata()
Unmark data in the session as flashdata.
public
unmarkFlashdata(array<string|int, mixed>|string $key) : mixed
Parameters
- $key : array<string|int, mixed>|string
-
Property identifier or array of them
unmarkTempdata()
Unmarks temporary data in the session, effectively removing its lifespan and allowing it to live as long as the session does.
public
unmarkTempdata(array<string|int, mixed>|string $key) : mixed
Parameters
- $key : array<string|int, mixed>|string
-
Property identifier or array of them