JSession
Extends \JObjectClass 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.
package |
Joomla.Platform |
---|---|
subpackage |
Session |
since |
11.1 |
Methods
__construct
Class constructor, overridden in descendant classes.
__construct(mixed $properties = null)
since |
11.1 |
---|
Arguments
- $properties
mixed
Either and associative array or another object to set the initial properties of the object.
__destruct
Session object destructor
__destruct()
since |
11.1 |
---|
__toString
Magic method to convert the object to a string gracefully.
__toString() : string
since |
11.1 |
---|---|
deprecated |
12.3 Classes should provide their own __toString() implementation. |
Response
string
The classname.
_createId
Create a session id
_createId() : string
since |
11.1 |
---|
Response
string
Session ID
_createToken
Create a token-string
_createToken(integer $length = 32) : string
since |
11.1 |
---|
Arguments
- $length
integer
Length of string
Response
string
Generated token
_setCookieParams
Set session cookie parameters
_setCookieParams() : void
since |
11.1 |
---|
_setCounter
Set counter of session usage
_setCounter() : boolean
since |
11.1 |
---|
Response
boolean
True on success
_setOptions
Set additional session options
_setOptions( &$options) : boolean
since |
11.1 |
---|
Arguments
- $options
Response
boolean
True on success
_setTimers
Set the session timers
_setTimers() : boolean
since |
11.1 |
---|
Response
boolean
True on success
_start
Start a session.
_start() : boolean
Creates a session (or resumes the current one based on the state of the session)
since |
11.1 |
---|
Response
boolean
true on success
_validate
Do some checks for security reason
_validate(boolean $restart = false) : boolean
- timeout check (expire)
- ip-fixiation
- browser-fixiation
If one check failed, session data has to be cleaned.
see | |
---|---|
since |
11.1 |
Arguments
- $restart
boolean
Reactivate session
Response
boolean
True on success
checkToken
Checks for a form token in the request.
checkToken(string $method = 'post') : boolean
Use in conjunction with JHtml::_('form.token') or JSession::getFormToken.
since |
12.1 |
---|
Arguments
- $method
string
The request method in which to look for the token key.
Response
boolean
True if found and valid, false otherwise.
clear
Unset data from the session store
clear(string $name, string $namespace = 'default') : mixed
since |
11.1 |
---|
Arguments
- $name
string
Name of variable- $namespace
string
Namespace to use, default to 'default'
Response
mixed
The value from session or NULL if not set
close
Writes session data and ends session
close() : void
Session data is usually stored after your script terminated without the need to call JSession::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 |
11.1 |
def
Sets a default value if not alreay assigned
def(string $property, mixed $default = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
destroy
Frees all session variables and destroys all data registered to a session
destroy() : boolean
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. It does not unset the session cookie.
see | \session_destroy() \session_unset() |
---|---|
since |
11.1 |
Response
boolean
True on success
fork
Create a new session and copy variables from the old one
fork() : boolean
since |
11.1 |
---|
Response
boolean
$result true on success
get
Returns a property of the object or the default value if the property is not set.
get(string $property, mixed $default = null) : mixed
since |
11.1 |
---|---|
see | \JObject::getProperties() |
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
The value of the property.
getError
Get the most recent error message.
getError(integer $i = null, boolean $toString = true) : string
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $i
integer
Option error index.- $toString
boolean
Indicates if JError objects should return their error message.
Response
string
Error message
getErrors
Return all errors, if any.
getErrors() : array
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Response
array
Array of error messages or JErrors.
getExpire
Get expiration time in minutes
getExpire() : integer
since |
11.1 |
---|
Response
integer
The session expiration time in minutes
getFormToken
Method to determine a hash for anti-spoofing variable names
getFormToken(boolean $forceNew = false) : string
since |
11.1 |
---|
Arguments
- $forceNew
boolean
If true, force a new token to be created
Response
string
Hashed var name
getId
Get session id
getId() : string
since |
11.1 |
---|
Response
string
The session name
getInstance
Returns the global Session object, only creating it if it doesn't already exist.
getInstance(string $handler, array $options) : \JSession
since |
11.1 |
---|
Arguments
- $handler
string
The type of session handler.- $options
array
An array of configuration options.
Response
\JSession
The Session object.
getName
Get session name
getName() : string
since |
11.1 |
---|
Response
string
The session name
getProperties
Returns an associative array of object properties.
getProperties(boolean $public = true) : array
since |
11.1 |
---|---|
see | \JObject::get() |
Arguments
- $public
boolean
If true, returns only the public properties.
Response
array
getState
Get current state of session
getState() : string
since |
11.1 |
---|
Response
string
The session state
getStores
Get the session handlers
getStores() : array
since |
11.1 |
---|
Response
array
An array of available session handlers
getToken
Get a session token, if a token isn't set yet one will be generated.
getToken(boolean $forceNew = false) : string
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.
since |
11.1 |
---|
Arguments
- $forceNew
boolean
If true, force a new token to be created
Response
string
The session token
has
Check whether data exists in the session store
has(string $name, string $namespace = 'default') : boolean
since |
11.1 |
---|
Arguments
- $name
string
Name of variable- $namespace
string
Namespace to use, default to 'default'
Response
boolean
True if the variable exists
hasToken
Method to determine if a token exists in the session. If not the session will be set to expired
hasToken(string $tCheck, boolean $forceExpire = true) : boolean
since |
11.1 |
---|
Arguments
- $tCheck
string
Hashed token to be verified- $forceExpire
boolean
If true, expires the session
Response
boolean
isNew
Check whether this session is currently created
isNew() : boolean
since |
11.1 |
---|
Response
boolean
True on success.
restart
Restart an expired or locked session.
restart() : boolean
see | \destroy |
---|---|
since |
11.1 |
Response
boolean
True on success
set
Modifies a property of the object, creating it if it does not already exist.
set(string $property, mixed $value = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $value
mixed
The value of the property to set.
Response
mixed
Previous value of the property.
setError
Add an error message.
setError(string $error) : void
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $error
string
Error message.
setProperties
Set the object properties based on a named array/hash.
setProperties(mixed $properties) : boolean
since |
11.1 |
---|---|
see | \JObject::set() |
Arguments
- $properties
mixed
Either an associative array or another object.
Response
boolean
toString
Converts the object to a string (the class name).
toString() : string
Properties
_state
Internal state.
_expire
Maximum age of unused session in minutes
since |
11.1 |
---|
Type(s)
string
_security
Security policy.
List of checks that will be done.
Default values:
- fix_browser
- fix_adress
since |
11.1 |
---|
Type(s)
array
_force_ssl
Force cookies to be SSL only Default false
since |
11.1 |
---|
Type(s)
boolean
_errors
An array of error messages or Exception objects.