\CodeIgniter\SessionSessionInterface

Expected behavior of a session container used with CodeIgniter.

Summary

Methods
Constants
regenerate()
destroy()
set()
get()
has()
remove()
setFlashdata()
getFlashdata()
keepFlashdata()
markAsFlashdata()
unmarkFlashdata()
getFlashKeys()
setTempdata()
getTempdata()
removeTempdata()
markAsTempdata()
unmarkTempdata()
getTempKeys()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

regenerate()

regenerate(boolean  $destroy = false) 

Regenerates the session ID.

Parameters

boolean $destroy

Should old session data be destroyed?

destroy()

destroy() 

Destroys the current session.

set()

set(string|array  $data, string|array  $value = null) 

Sets user data into the session.

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

string|array $data

Property name or associative array of properties

string|array $value

Property value if single key provided

get()

get(string  $key = null) : array|null

Get user data that has been set in the session.

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

string $key

Identifier of the session property to retrieve

Returns

array|null —

The property value(s)

has()

has(string  $key) : boolean

Returns whether an index exists in the session array.

Parameters

string $key

Identifier of the session property we are interested in.

Returns

boolean

remove()

remove(string|array  $key) 

Remove one or more session properties.

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

string|array $key

Identifier of the session property or properties to remove.

setFlashdata()

setFlashdata(string|array  $data, string|array  $value = null) 

Sets data into the session that will only last for a single request.

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

string|array $data

Property identifier or associative array of properties

string|array $value

Property value if $data is a scalar

getFlashdata()

getFlashdata(string  $key = null) : array|null

Retrieve one or more items of flash data from the session.

If the item key is null, return all flashdata.

Parameters

string $key

Property identifier

Returns

array|null —

The requested property value, or an associative array of them

keepFlashdata()

keepFlashdata(array|string  $key) 

Keeps a single piece of flash data alive for one more request.

Parameters

array|string $key

Property identifier or array of them

markAsFlashdata()

markAsFlashdata(string|array  $key) : False

Mark a session property or properties as flashdata.

Parameters

string|array $key

Property identifier or array of them

Returns

False —

if any of the properties are not already set

unmarkFlashdata()

unmarkFlashdata(string|array  $key) 

Unmark data in the session as flashdata.

Parameters

string|array $key

Property identifier or array of them

getFlashKeys()

getFlashKeys() : array

Retrieve all of the keys for session data marked as flashdata.

Returns

array —

The property names of all flashdata

setTempdata()

setTempdata(string|array  $data, mixed  $value = null, integer  $ttl = 300) 

Sets new data into the session, and marks it as temporary data with a set lifespan.

Parameters

string|array $data

Session data key or associative array of items

mixed $value

Value to store

integer $ttl

Time-to-live in seconds

getTempdata()

getTempdata(string  $key = null) : mixed

Returns either a single piece of tempdata, or all temp data currently in the session.

Parameters

string $key

Session data key

Returns

mixed —

Session data value or null if not found.

removeTempdata()

removeTempdata(string  $key) 

Removes a single piece of temporary data from the session.

Parameters

string $key

Session data key

markAsTempdata()

markAsTempdata(string|array  $key, integer  $ttl = 300) : boolean

Mark one of more pieces of data as being temporary, meaning that it has a set lifespan within the session.

Parameters

string|array $key

Property identifier or array of them

integer $ttl

Time to live, in seconds

Returns

boolean —

False if any of the properties were not set

unmarkTempdata()

unmarkTempdata(string|array  $key) 

Unmarks temporary data in the session, effectively removing its lifespan and allowing it to live as long as the session does.

Parameters

string|array $key

Property identifier or array of them

getTempKeys()

getTempKeys() : array

Retrieve the keys of all session data that have been marked as temporary data.

Returns

array