Session
Implements SessionInterface, DispatcherAwareInterfaceClass for managing HTTP sessions
Provides access to session-state values as well as session-level settings and lifetime management methods. Based on the standard PHP session handling mechanism it provides more advanced features such as expire timeouts.
| since |
1.0 |
|---|---|
| package |
Joomla Framework |
Methods
__construct
Constructor
__construct(\Joomla\Session\StorageInterface store = null, \Joomla\Event\DispatcherInterface dispatcher = null, mixed||string|int options = []) :
| since |
1.0 |
|---|
Arguments
- store
StorageInterface|nullA StorageInterface implementation.- dispatcher
DispatcherInterface|nullDispatcherInterface for the session to use.- options
array<string|int, mixed>Optional parameters. Supported keys include:- name: The session name
- id: The session ID
- expire: The session lifetime in seconds
Response
mixed
abort
Aborts the current session
abort() :
| see | session_abort() |
|---|---|
| since |
2.0.0 |
Response
bool
addValidator
Adds a validator to the session
addValidator(\Joomla\Session\ValidatorInterface validator) :
all
Retrieves all variables from the session store
all() : mixed||string|int
| since |
2.0.0 |
|---|
Response
array<string|int, mixed>
clear
Clears all variables from the session store
clear() :
| since |
1.0 |
|---|
Response
void
close
Writes session data and ends session
close() :
Session data is usually stored after your script terminated without the need to call {@link Session::close()}, but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.
| see | session_write_close() |
|---|---|
| since |
1.0 |
Response
void
createToken
Create a token string
createToken() :
| since |
1.3.1 |
|---|
Response
string
destroy
Frees all session variables and destroys all data registered to a session
destroy() :
This method resets the $_SESSION variable and destroys all of the data associated with the current session in its storage (file or DB). It forces new session to be started after this method is called.
| see | session_destroy() session_unset() |
|---|---|
| since |
1.0 |
Response
bool
fork
Create a new session and copy variables from the old one
fork( destroy = false) :
| since |
1.0 |
|---|
Arguments
- destroy
boolWhether to delete the old session or leave it to garbage collection.
Response
boolTrue on success
gc
Perform session data garbage collection
gc() : int|bool
| see | session_gc() |
|---|---|
| since |
2.0.0 |
Response
int|boolNumber of deleted sessions on success or boolean false on failure or if the function is unsupported
get
Get data from the session store
get( name, default = null) :
| since |
1.0 |
|---|
Arguments
- name
stringName of a variable- default
mixedDefault value of a variable if not set
Response
mixedValue of a variable
getDispatcher
Get the event dispatcher.
getDispatcher() : \Joomla\Event\DispatcherInterface
| since |
1.2.0 |
|---|---|
| throws |
|
Response
getExpire
Get expiration time in seconds
getExpire() :
| since |
1.0 |
|---|
Response
intThe session expiration time in seconds
getId
Get session id
getId() :
| since |
1.0 |
|---|
Response
stringThe session id
getIterator
Retrieve an external iterator.
getIterator() : \ArrayIterator
| since |
1.0 |
|---|
Response
ArrayIteratorReturn an ArrayIterator of $_SESSION.
getName
Get session name
getName() :
| since |
1.0 |
|---|
Response
stringThe session name
getState
Get current state of session
getState() :
| since |
1.0 |
|---|
Response
stringThe session state
getToken
Get a session token.
getToken( forceNew = false) :
Tokens are used to secure forms from spamming attacks. Once a token has been generated the system will check the request to see if it is present, if not it will invalidate the session.
| since |
1.0 |
|---|
Arguments
- forceNew
boolIf true, forces a new token to be created
Response
string
has
Check whether data exists in the session store
has( name) :
| since |
1.0 |
|---|
Arguments
- name
stringName of variable
Response
boolTrue if the variable exists
hasToken
Check if the session has the given token.
hasToken( token, forceExpire = true) :
| since |
1.0 |
|---|
Arguments
- token
stringHashed token to be verified- forceExpire
boolIf true, expires the session
Response
bool
isActive
Check if the session is active
isActive() :
| since |
1.0 |
|---|
Response
bool
isNew
Check whether this session is currently created
isNew() :
| since |
1.0 |
|---|
Response
bool
isStarted
Check if the session is started
isStarted() :
| since |
2.0.0 |
|---|
Response
bool
remove
Unset a variable from the session store
remove( name) :
| since |
2.0.0 |
|---|
Arguments
- name
stringName of variable
Response
mixedThe value from session or NULL if not set
restart
Restart an expired or locked session.
restart() :
| see | destroy |
|---|---|
| since |
1.0 |
Response
boolTrue on success
set
Set data into the session store.
set( name, value = null) :
| since |
1.0 |
|---|
Arguments
- name
stringName of a variable.- value
mixedValue of a variable.
Response
mixedOld value of a variable.
setCounter
Set counter of session usage
setCounter() :
| since |
1.0 |
|---|
Response
boolTrue on success
setDispatcher
Set the dispatcher to use.
setDispatcher(\Joomla\Event\DispatcherInterface dispatcher) :
setExpire
Set the session expiration
setExpire( expire) :
| since |
1.3.0 |
|---|
Arguments
- expire
intMaximum age of unused session in seconds
Response
$this
setId
Set the session ID
setId( id) :
| since |
2.0.0 |
|---|
Arguments
- id
stringThe session ID
Response
$this
setName
Set the session name
setName( name) :
| since |
2.0.0 |
|---|
Arguments
- name
stringThe session name
Response
$this
setOptions
Set additional session options
setOptions(mixed||string|int options) :
| since |
1.0 |
|---|
Arguments
- options
array<string|int, mixed>List of parameter
Response
boolTrue on success
setState
Set the session state
setState( state) :
| since |
1.3.0 |
|---|
Arguments
- state
stringInternal state
Response
$this
setTimers
Set the session timers
setTimers() :
| since |
1.0 |
|---|
Response
boolTrue on success
start
Start a session.
start() :
| since |
1.0 |
|---|
Response
void
validate
Do some checks for security reasons
validate( restart = false) :
If one check fails, session data has to be cleaned.
| see |
http://shiflett.org/articles/the-truth-about-sessions |
|---|---|
| since |
1.0 |
Arguments
- restart
boolReactivate session
Response
boolTrue on success
Properties
state
Internal session state.
| since |
1.0 |
|---|
Type(s)
string
expire
Maximum age of unused session in seconds.
| since |
1.0 |
|---|
Type(s)
int
sessionValidators
Container holding session validators.