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, array options = []) : mixed
| since |
1.0 |
|---|
Arguments
- store
\Joomla\Session\StorageInterfaceA StorageInterface implementation.- dispatcher
\Joomla\Event\DispatcherInterfaceDispatcherInterface for the session to use.- options
arrayOptional 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() : bool
| see | session_abort() |
|---|---|
| since |
2.0.0 |
Response
bool
addValidator
Adds a validator to the session
addValidator(\Joomla\Session\ValidatorInterface validator) : void
| since |
2.0.0 |
|---|
Arguments
- validator
\Joomla\Session\ValidatorInterfaceThe session validator
all
Retrieves all variables from the session store
all() : array
| since |
2.0.0 |
|---|
Response
array
clear
Clears all variables from the session store
clear() : void
| since |
1.0 |
|---|
close
Writes session data and ends session
close() : void
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 |
createToken
Create a token string
createToken() : string
| since |
1.3.1 |
|---|
Response
string
destroy
Frees all session variables and destroys all data registered to a session
destroy() : bool
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(bool destroy = false) : bool
| 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(string name, mixed default = null) : mixed
| 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
\Joomla\Event\DispatcherInterface
getExpire
Get expiration time in seconds
getExpire() : int
| since |
1.0 |
|---|
Response
intThe session expiration time in seconds
getId
Get session id
getId() : string
| 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() : string
| since |
1.0 |
|---|
Response
stringThe session name
getState
Get current state of session
getState() : string
| since |
1.0 |
|---|
Response
stringThe session state
getToken
Get a session token.
getToken(bool forceNew = false) : string
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(string name) : bool
| since |
1.0 |
|---|
Arguments
- name
stringName of variable
Response
boolTrue if the variable exists
hasToken
Check if the session has the given token.
hasToken(string token, bool forceExpire = true) : bool
| 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() : bool
| since |
1.0 |
|---|
Response
bool
isNew
Check whether this session is currently created
isNew() : bool
| since |
1.0 |
|---|
Response
bool
isStarted
Check if the session is started
isStarted() : bool
| since |
2.0.0 |
|---|
Response
bool
remove
Unset a variable from the session store
remove(string name) : mixed
| 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() : bool
| see | destroy |
|---|---|
| since |
1.0 |
Response
boolTrue on success
set
Set data into the session store.
set(string name, mixed value = null) : mixed
| 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() : bool
| since |
1.0 |
|---|
Response
boolTrue on success
setDispatcher
Set the dispatcher to use.
setDispatcher(\Joomla\Event\DispatcherInterface dispatcher) : $this
| since |
1.2.0 |
|---|
Arguments
- dispatcher
\Joomla\Event\DispatcherInterfaceThe dispatcher to use.
Response
$this
setExpire
Set the session expiration
setExpire(int expire) : $this
| since |
1.3.0 |
|---|
Arguments
- expire
intMaximum age of unused session in seconds
Response
$this
setId
Set the session ID
setId(string id) : $this
| since |
2.0.0 |
|---|
Arguments
- id
stringThe session ID
Response
$this
setName
Set the session name
setName(string name) : $this
| since |
2.0.0 |
|---|
Arguments
- name
stringThe session name
Response
$this
setOptions
Set additional session options
setOptions(array options) : bool
| since |
1.0 |
|---|
Arguments
- options
arrayList of parameter
Response
boolTrue on success
setState
Set the session state
setState(string state) : $this
| since |
1.3.0 |
|---|
Arguments
- state
stringInternal state
Response
$this
setTimers
Set the session timers
setTimers() : bool
| since |
1.0 |
|---|
Response
boolTrue on success
start
Start a session.
start() : void
| since |
1.0 |
|---|
validate
Do some checks for security reasons
validate(bool restart = false) : bool
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
store
The session store object.
| since |
1.0 |
|---|
Type(s)
\Joomla\Session\StorageInterface
sessionValidators
Container holding session validators.
| since |
2.0.0 |
|---|
Type(s)
\Joomla\Session\ValidatorInterface[]
dispatcher
Event Dispatcher
| since |
1.2.0 |
|---|
Type(s)
\Joomla\Event\DispatcherInterface|null