class JSession extends JObject


Located at : UKNOWVA_ROOT/libraries/joomla/session/session.php

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

__construct($store = 'none', $options = array())

Constructor

string
__toString()

Magic method to convert the object to a string gracefully.

from JObject
mixed
def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

from JObject
mixed
get(string $name, mixed $default = null, string $namespace = 'default')

Get data from the session store

array
getProperties(boolean $public = true)

Returns an associative array of object properties.

from JObject
string
getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

from JObject
array
getErrors()

Return all errors, if any.

from JObject
mixed
set(string $name, mixed $value = null, string $namespace = 'default')

Set data into the session store.

boolean
setProperties(mixed $properties)

Set the object properties based on a named array/hash.

from JObject
void
setError(string $error)

Add an error message.

from JObject
string
toString() deprecated

No description

from JObject
__destruct()

Session object destructor

static JSession
getInstance($handler, $options)

Returns the global Session object, only creating it if it doesn't already exist.

string
getState()

Get current state of session

integer
getExpire()

Get expiration time in minutes

string
getToken(boolean $forceNew = false)

Get a session token, if a token isn't set yet one will be generated.

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

string
getName()

Get session name

string
getId()

Get session id

static array
getStores()

Get the session handlers

boolean
isNew()

Check whether this session is currently created

boolean
has(string $name, string $namespace = 'default')

Check whether data exists in the session store

mixed
clear(string $name, string $namespace = 'default')

Unset data from the session store

boolean
destroy()

Frees all session variables and destroys all data registered to a session

boolean
restart()

Restart an expired or locked session.

boolean
fork()

Create a new session and copy variables from the old one

void
close()

Writes session data and ends session

Details

at line 87
JObject __construct($store = 'none', $options = array())

Constructor

Parameters

$store
$options

Return Value

JObject

in JObject at line 56
string __toString()

Magic method to convert the object to a string gracefully.

Return Value

string The classname.

in JObject at line 70
mixed def(string $property, mixed $default = null)

Sets a default value if not alreay assigned

Parameters

string $property The name of the property.
mixed $default The default value.

Return Value

mixed

at line 338
mixed get(string $name, mixed $default = null, string $namespace = 'default')

Get data from the session store

Parameters

string $name Name of a variable
mixed $default The default value.
string $namespace Namespace to use, default to 'default'

Return Value

mixed The value of the property.

in JObject at line 107
array getProperties(boolean $public = true)

Returns an associative array of object properties.

Parameters

boolean $public If true, returns only the public properties.

Return Value

array

See also

get()

in JObject at line 133
string getError(integer $i = null, boolean $toString = true)

Get the most recent error message.

Parameters

integer $i Option error index.
boolean $toString Indicates if JError objects should return their error message.

Return Value

string Error message

in JObject at line 165
array getErrors()

Return all errors, if any.

Return Value

array Array of error messages or JErrors.

at line 365
mixed set(string $name, mixed $value = null, string $namespace = 'default')

Set data into the session store.

Parameters

string $name Name of a variable.
mixed $value The value of the property to set.
string $namespace Namespace to use, default to 'default'.

Return Value

mixed Previous value of the property.

in JObject at line 198
boolean setProperties(mixed $properties)

Set the object properties based on a named array/hash.

Parameters

mixed $properties Either an associative array or another object.

Return Value

boolean

See also

set()

in JObject at line 222
void setError(string $error)

Add an error message.

Parameters

string $error Error message.

Return Value

void

in JObject at line 235
string toString() deprecated

deprecated 12.1 Use magic method __toString()

Return Value

string

See also

__toString()

at line 127
__destruct()

Session object destructor

at line 143
static JSession getInstance($handler, $options)

Returns the global Session object, only creating it if it doesn't already exist.

Parameters

$handler
$options

Return Value

JSession The Session object.

at line 161
string getState()

Get current state of session

Return Value

string The session state

at line 173
integer getExpire()

Get expiration time in minutes

Return Value

integer The session expiration time in minutes

at line 191
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.

Parameters

boolean $forceNew If true, force a new token to be created

Return Value

string The session token

at line 215
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

Parameters

string $tCheck Hashed token to be verified
boolean $forceExpire If true, expires the session

Return Value

boolean

at line 240
static string getFormToken(boolean $forceNew = false)

Method to determine a hash for anti-spoofing variable names

Parameters

boolean $forceNew If true, force a new token to be created

Return Value

string Hashed var name

at line 256
string getName()

Get session name

Return Value

string The session name

at line 272
string getId()

Get session id

Return Value

string The session name

at line 288
static array getStores()

Get the session handlers

Return Value

array An array of available session handlers

at line 318
boolean isNew()

Check whether this session is currently created

Return Value

boolean True on success.

at line 395
boolean has(string $name, string $namespace = 'default')

Check whether data exists in the session store

Parameters

string $name Name of variable
string $namespace Namespace to use, default to 'default'

Return Value

boolean True if the variable exists

at line 418
mixed clear(string $name, string $namespace = 'default')

Unset data from the session store

Parameters

string $name Name of variable
string $namespace Namespace to use, default to 'default'

Return Value

mixed The value from session or NULL if not set

at line 480
boolean destroy()

Frees all session variables and destroys all data registered to a session

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.

Return Value

boolean True on success

See also

session_destroy()
session_unset()

at line 512
boolean restart()

Restart an expired or locked session.

Return Value

boolean True on success

See also

destroy

at line 543
boolean fork()

Create a new session and copy variables from the old one

Return Value

boolean $result true on success

at line 596
void close()

Writes session data and ends session

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.

Return Value

void

See also

session_write_close()