Session
class Session implements IteratorAggregate
Class 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.
Methods
Constructor
Magic method to get read-only access to properties.
Returns the global Session object, only creating it if it doesn't already exist.
Get current state of session
Get expiration time in seconds
Get a session token, if a token isn't set yet one will be generated.
Method to determine if a token exists in the session. If not the session will be set to expired
Method to determine a hash for anti-spoofing variable names
Retrieve an external iterator.
Checks for a form token in the request.
Get session name
Get session id
Returns a clone of the internal data pointer
Get the session handlers
Shorthand to check if the session is active
Check whether this session is currently created
Check whether this session is currently created
Get data from the session store
Set data into the session store.
Check whether data exists in the session store
Unset data from the session store
Start a session.
Frees all session variables and destroys all data registered to a session
Restart an expired or locked session.
Create a new session and copy variables from the old one
Writes session data and ends session
Delete expired session data
Details
__construct(
string $store = 'none',
array $options = array(),
JSessionHandlerInterface $handlerInterface = null)
Constructor
static
Session
getInstance(
string $store,
array $options,
JSessionHandlerInterface $handlerInterface = null)
Returns the global Session object, only creating it if it doesn't already exist.
string
getToken(
boolean $forceNew = false)
Get a session token, if a token isn't set yet one will be generated.
Tokens are used to secure forms from spamming attacks. Once a token has been generated the system will check the post request to see if it is present, if not it will invalidate the session.
boolean
hasToken(
string $tCheck,
boolean $forceExpire = true)
Method to determine if a token exists in the session. If not the session will be set to expired
static
string
getFormToken(
boolean $forceNew = false)
Method to determine a hash for anti-spoofing variable names
static
boolean
checkToken(
string $method = 'post')
Checks for a form token in the request.
Use in conjunction with \JHtml::_('form.token') or Session::getFormToken.
void
initialise(
Input $input,
JEventDispatcher $dispatcher = null)
Check whether this session is currently created
mixed
get(
string $name,
mixed $default = null,
string $namespace = 'default')
Get data from the session store
mixed
set(
string $name,
mixed $value = null,
string $namespace = 'default')
Set data into the session store.
boolean
has(
string $name,
string $namespace = 'default')
Check whether data exists in the session store
boolean
destroy()
Frees all session variables and destroys all data registered to a session
This method resets the data pointer and destroys all of the data associated with the current session in its storage. It forces a new session to be started after this method is called. It does not unset the session cookie.
void
close()
Writes session data and ends session
Session data is usually stored after your script terminated without the need to call 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.