SessionInterface
interface SessionInterface (View source)
Methods
Tells if the session has been started already.
Starts the session, if it has not been already started
Returns true if there is a session that can be resumed. false otherwise
Resumes an existing session, if any.
Returns the current session ID.
Generates and propagates a new session ID and transfers all existing data to the new session.
Returns the content (mixed) associated with the given key.
Returns true if $key is available.
Stores the given data under the given key in the session
Tags this session with the given tag.
Removes the specified tag from this session.
Returns the tags this session has been tagged with.
Updates the last activity time to "now".
Returns the unix time stamp marking the last point in time this session has been in use.
Explicitly writes (persists) and closes the session
Explicitly destroys all session data
Details
bool
isStarted()
Tells if the session has been started already.
void
start()
Starts the session, if it has not been already started
bool
canBeResumed()
Returns true if there is a session that can be resumed. false otherwise
int|null
resume()
Resumes an existing session, if any.
string
getId()
Returns the current session ID.
string
renewId()
Generates and propagates a new session ID and transfers all existing data to the new session.
Renewing the session ID is one counter measure against Session Fixation Attacks.
mixed
getData(string $key)
Returns the content (mixed) associated with the given key.
bool
hasKey(string $key)
Returns true if $key is available.
void
putData(string $key, mixed $data)
Stores the given data under the given key in the session
void
addTag(string $tag)
Tags this session with the given tag.
Note that third-party libraries might also tag your session. Therefore it is recommended to use namespaced tags such as "Acme-Demo-MySpecialTag".
void
removeTag(string $tag)
Removes the specified tag from this session.
array
getTags()
Returns the tags this session has been tagged with.
void
touch()
Updates the last activity time to "now".
int
getLastActivityTimestamp()
Returns the unix time stamp marking the last point in time this session has been in use.
For the current (local) session, this method will always return the current time. For a remote session, the unix timestamp will be returned.
void
close()
Explicitly writes (persists) and closes the session
void
destroy(string|null $reason = null)
Explicitly destroys all session data