Class JSession

Description

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.

  • since: 11.1

Located in /libraries/joomla/session/session.php (line 26)

JObject
   |
   --JSession
Variable Summary
Method Summary
static boolean checkToken ([string $method = 'post'])
static string getFormToken ([boolean $forceNew = false])
static JSession getInstance (string $handler, array $options)
static array getStores ()
JSession __construct ([string $store = 'none'], [array $options = array()])
void __destruct ()
mixed clear (string $name, [string $namespace = 'default'])
void close ()
boolean destroy ()
boolean fork ()
mixed get (string $name, [mixed $default = null], [string $namespace = 'default'])
integer getExpire ()
string getId ()
string getName ()
string getState ()
string getToken ([boolean $forceNew = false])
boolean has (string $name, [string $namespace = 'default'])
boolean hasToken (string $tCheck, [boolean $forceExpire = true])
boolean isNew ()
boolean restart ()
mixed set (string $name, [mixed $value = null], [string $namespace = 'default'])
string _createId ()
string _createToken ([integer $length = 32])
boolean _setCounter ()
boolean _setOptions (array &$options)
boolean _setTimers ()
boolean _start ()
boolean _validate ([boolean $restart = false])
Variables
static JSession $instance (line 80)
  • var: JSession instances container.
  • since: 11.3
  • access: protected
string $_expire = 15 (line 44)

Maximum age of unused session in minutes

  • since: 11.1
  • access: protected
boolean $_force_ssl = false (line 74)

Force cookies to be SSL only Default false

  • since: 11.1
  • access: protected
array $_security = array('fix_browser') (line 65)

Security policy.

List of checks that will be done.

Default values:

  • fix_browser
  • fix_adress

  • since: 11.1
  • access: protected
string $_state = 'active' (line 36)

Internal state.

One of 'active'|'expired'|'destroyed'|'error'

JSessionStorage $_store = null (line 52)

The session store object.

  • since: 11.1
  • access: protected

Inherited Variables

Inherited from JObject

JObject::$_errors
Methods
static method checkToken (line 266)

Checks for a form token in the request.

Use in conjunction with JHtml::_('form.token') or JSession::getFormToken.

  • return: True if found and valid, false otherwise.
  • since: 12.1
  • access: public
static boolean checkToken ([string $method = 'post'])
  • string $method: The request method in which to look for the token key.
static method getFormToken (line 246)

Method to determine a hash for anti-spoofing variable names

  • return: Hashed var name
  • since: 11.1
  • access: public
static string getFormToken ([boolean $forceNew = false])
  • boolean $forceNew: If true, force a new token to be created
static method getInstance (line 147)

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

  • return: The Session object.
  • since: 11.1
  • access: public
static JSession getInstance (string $handler, array $options)
  • string $handler: The type of session handler.
  • array $options: An array of configuration options.
static method getStores (line 338)

Get the session handlers

  • return: An array of available session handlers
  • since: 11.1
  • access: public
static array getStores ()
Constructor __construct (line 90)

Constructor

  • since: 11.1
  • access: public
JSession __construct ([string $store = 'none'], [array $options = array()])
  • string $store: The type of storage for the session.
  • array $options: Optional parameters

Redefinition of:
JObject::__construct()
Class constructor, overridden in descendant classes.
Destructor __destruct (line 131)

Session object destructor

  • since: 11.1
  • access: public
void __destruct ()
clear (line 481)

Unset data from the session store

  • return: The value from session or NULL if not set
  • since: 11.1
  • access: public
mixed clear (string $name, [string $namespace = 'default'])
  • string $name: Name of variable
  • string $namespace: Namespace to use, default to 'default'
close (line 674)

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.

void close ()
destroy (line 550)

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.

boolean destroy ()
fork (line 619)

Create a new session and copy variables from the old one

  • return: true on success
  • since: 11.1
  • access: public
boolean fork ()
get (line 392)

Get data from the session store

  • return: Value of a variable
  • since: 11.1
  • access: public
mixed get (string $name, [mixed $default = null], [string $namespace = 'default'])
  • string $name: Name of a variable
  • mixed $default: Default value of a variable if not set
  • string $namespace: Namespace to use, default to 'default'

Redefinition of:
JObject::get()
Returns a property of the object or the default value if the property is not set.
getExpire (line 176)

Get expiration time in minutes

  • return: The session expiration time in minutes
  • since: 11.1
  • access: public
integer getExpire ()
getId (line 321)

Get session id

  • return: The session name
  • since: 11.1
  • access: public
string getId ()
getName (line 304)

Get session name

  • return: The session name
  • since: 11.1
  • access: public
string getName ()
getState (line 164)

Get current state of session

  • return: The session state
  • since: 11.1
  • access: public
string getState ()
getToken (line 194)

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.

  • return: The session token
  • since: 11.1
  • access: public
string getToken ([boolean $forceNew = false])
  • boolean $forceNew: If true, force a new token to be created
has (line 457)

Check whether data exists in the session store

  • return: True if the variable exists
  • since: 11.1
  • access: public
boolean has (string $name, [string $namespace = 'default'])
  • string $name: Name of variable
  • string $namespace: Namespace to use, default to 'default'
hasToken (line 219)

Method to determine if a token exists in the session. If not the session will be set to expired

  • since: 11.1
  • access: public
boolean hasToken (string $tCheck, [boolean $forceExpire = true])
  • string $tCheck: Hashed token to be verified
  • boolean $forceExpire: If true, expires the session
isNew (line 371)

Check whether this session is currently created

  • return: True on success.
  • since: 11.1
  • access: public
boolean isNew ()
restart (line 586)

Restart an expired or locked session.

boolean restart ()
set (line 422)

Set data into the session store.

  • return: Old value of a variable.
  • since: 11.1
  • access: public
mixed set (string $name, [mixed $value = null], [string $namespace = 'default'])
  • string $name: Name of a variable.
  • mixed $value: Value of a variable.
  • string $namespace: Namespace to use, default to 'default'.

Redefinition of:
JObject::set()
Modifies a property of the object, creating it if it does not already exist.
_createId (line 686)

Create a session id

  • return: Session ID
  • since: 11.1
  • access: protected
string _createId ()
_createToken (line 736)

Create a token-string

  • return: Generated token
  • since: 11.1
  • access: protected
string _createToken ([integer $length = 32])
  • integer $length: Length of string
_setCookieParams (line 705)

Set session cookie parameters

  • since: 11.1
  • access: protected
void _setCookieParams ()
_setCounter (line 757)

Set counter of session usage

  • return: True on success
  • since: 11.1
  • access: protected
boolean _setCounter ()
_setOptions (line 799)

Set additional session options

  • return: True on success
  • since: 11.1
  • access: protected
boolean _setOptions (array &$options)
  • array &$options: List of parameter
_setTimers (line 773)

Set the session timers

  • return: True on success
  • since: 11.1
  • access: protected
boolean _setTimers ()
_start (line 511)

Start a session.

Creates a session (or resumes the current one based on the state of the session)

  • return: true on success
  • since: 11.1
  • access: protected
boolean _start ()
_validate (line 852)

Do some checks for security reason

  • timeout check (expire)
  • ip-fixiation
  • browser-fixiation
If one check failed, session data has to be cleaned.

boolean _validate ([boolean $restart = false])
  • boolean $restart: Reactivate session

Inherited Methods

Inherited From JObject

JObject::__construct()
JObject::def()
JObject::get()
JObject::getError()
JObject::getErrors()
JObject::getProperties()
JObject::set()
JObject::setError()
JObject::setProperties()
JObject::toString()
JObject::__toString()

Documentation generated on Mon, 25 Jun 2012 13:59:28 -0500 by phpDocumentor 1.4.4