eZPublish  4.4
eZSession Class Reference

Static Public Member Functions

static addCallback ($type, $callback)
 Adds a callback function, to be triggered by eZSession::triggerCallback() when a certain session event occurs. More...
 
static cleanup ()
 Truncates all session data in the database, this function is not supported by session handlers that don't have a session backend on their own. More...
 
static countActive ()
 Counts the number of active session and returns it, this function is not supported by session handlers that don't have a session backend on their own. More...
 
static garbageCollector ()
 Deletes all expired session data in the database, this function is not supported by session handlers that don't have a session backend on their own. More...
 
static & get ($key=null, $defaultValue=null)
 Get session value (wrapper) More...
 
static getHandlerInstance ()
 Get curren session handler. More...
 
static getUserSessionHash ()
 Gets/generates the user hash for use in validating the session based on [Session] SessionValidation* site.ini settings. More...
 
static hasStarted ()
 Return value to indicate if session has started or not. More...
 
static issetkey ($key, $forceStart=true)
 Isset session value (wrapper) More...
 
static lazyStart ($startIfUserHasCookie=true)
 Inits eZSession and starts it if user has cookie and $startIfUserHasCookie is true. More...
 
static regenerate ($updateBackendData=true)
 Will make sure the user gets a new session ID while keepin the session data. More...
 
static remove ()
 Removes the current session and resets session variables. More...
 
static set ($key, $value)
 Set session value (wrapper) More...
 
static setUserID ($userID)
 Sets the current userID used by ezpSessionHandlerDB::write() on shutdown. More...
 
static start ($cookieTimeout=false)
 Starts the session and sets the timeout of the session cookie. More...
 
static stop ()
 Writes session data and stops the session, if not already stopped. More...
 
static triggerCallback ($type, $params)
 Triggers callback functions by type, registrated by eZSession::addCallback() Use: eZSession::triggerCallback('gc_pre', array( $db, $time ) );. More...
 
static unsetkey ($key, $forceStart=true)
 unset session value (wrapper) More...
 
static userHasSessionCookie ()
 Returns if user had session cookie at start of request or not. More...
 
static userID ()
 Gets the current user id. More...
 
static userSessionIsValid ()
 Returns if user session validated against stored data in db or if it was invalidated during the current request. More...
 

Protected Member Functions

 __construct ()
 Constructor (not used, this is an all static class) More...
 

Static Protected Member Functions

static forceStart ()
 See eZSession::start(). More...
 
static registerFunctions ()
 Register the needed session functions, this is called automatically by eZSession::start(), so only call this if you don't start the session. More...
 
static setCookieParams ($lifetime=false)
 Set default cookie parameters based on site.ini settings (fallback to php.ini settings) Used by eZSession::registerFunctions() Note: this will only have affect when session is created / re-created. More...
 

Static Protected Attributes

static $callbackFunctions = array()
 
static $handlerInstance = null
 
static $hasSessionCookie = null
 
static $hasStarted = false
 
static $userID = 0
 

Constructor & Destructor Documentation

eZSession::__construct ( )
protected

Constructor (not used, this is an all static class)

Member Function Documentation

static eZSession::addCallback (   $type,
  $callback 
)
static

Adds a callback function, to be triggered by eZSession::triggerCallback() when a certain session event occurs.

Use: eZSession::addCallback('gc_pre', myCustomGarabageFunction );

Since
4.1
Parameters
string$typecleanup, gc, destroy, insert and update, pre and post types.
handler$callbacka function to call.
static eZSession::cleanup ( )
static

Truncates all session data in the database, this function is not supported by session handlers that don't have a session backend on their own.

Since
4.1
Returns
bool
static eZSession::countActive ( )
static

Counts the number of active session and returns it, this function is not supported by session handlers that don't have a session backend on their own.

Since
4.1
Returns
string Number of sessions.
static eZSession::forceStart ( )
staticprotected

See eZSession::start().

Since
4.4
Returns
true
static eZSession::garbageCollector ( )
static

Deletes all expired session data in the database, this function is not supported by session handlers that don't have a session backend on their own.

Since
4.1
Returns
bool
static& eZSession::get (   $key = null,
  $defaultValue = null 
)
static

Get session value (wrapper)

Since
4.4
Parameters
string | null$keyReturn the whole session array if null otherwise the value of $key
null | mixed$defaultValueReturn this if not null and session has not started
Returns
mixed|null $defaultValue if key does not exist, otherwise session value depending on $key

Referenced by eZHTTPTool\attribute(), eZUser\groups(), eZUser\limitValueList(), eZUser\roleIDList(), and eZHTTPTool\sessionVariable().

static eZSession::getHandlerInstance ( )
static

Get curren session handler.

Since
4.4
Returns
ezpSessionHandler

Referenced by eZUser\removeSessionData().

static eZSession::getUserSessionHash ( )
static

Gets/generates the user hash for use in validating the session based on [Session] SessionValidation* site.ini settings.

The default hash is result of md5('empty').

Since
4.1
Deprecated:
as of 4.4, only returns default md5('empty') hash now for BC.
Returns
string MD5 hash based on parts of the user ip and agent string.
static eZSession::hasStarted ( )
static

Return value to indicate if session has started or not.

Since
4.4
Returns
bool

Referenced by eZCheckUser(), eZUser\instance(), and eZUserLoginHandler\preCheck().

static eZSession::issetkey (   $key,
  $forceStart = true 
)
static

Isset session value (wrapper)

Since
4.4
Parameters
string$key
bool$forceStartForce session start if true
Returns
bool|null Null if session has not started and $forceStart is false

Referenced by eZUser\checkUser(), and eZHTTPTool\hasSessionVariable().

static eZSession::lazyStart (   $startIfUserHasCookie = true)
static

Inits eZSession and starts it if user has cookie and $startIfUserHasCookie is true.

Since
4.4
Parameters
bool$startIfUserHasCookie
Returns
bool|null
static eZSession::regenerate (   $updateBackendData = true)
static

Will make sure the user gets a new session ID while keepin the session data.

This is useful to call on logins, to avoid sessions theft from users. NOTE: make sure you set new user id first using eZSession::setUserID()

Since
4.1
Parameters
bool$updateBackendDataset to false to not update session backend with new session id and user id.
Returns
bool Depending on if session was regenerated.

Referenced by eZUser\logoutCurrent(), and eZUser\setCurrentlyLoggedInUser().

static eZSession::registerFunctions ( )
staticprotected

Register the needed session functions, this is called automatically by eZSession::start(), so only call this if you don't start the session.

Since
4.1
Returns
bool Depending on if eZSession is registrated as session handler.
static eZSession::remove ( )
static

Removes the current session and resets session variables.

Note: implicit stops session as well!

Since
4.1
Returns
bool Depending on if session was removed.

Referenced by eZScript\shutdown().

static eZSession::set (   $key,
  $value 
)
static

Set session value (wrapper)

Since
4.4
Parameters
string$key
Returns
bool

Referenced by eZUser\setCurrentlyLoggedInUser(), and eZHTTPTool\setSessionVariable().

static eZSession::setCookieParams (   $lifetime = false)
staticprotected

Set default cookie parameters based on site.ini settings (fallback to php.ini settings) Used by eZSession::registerFunctions() Note: this will only have affect when session is created / re-created.

Since
4.4
Parameters
int | false$lifetimeCookie timeout of session cookie, will read from ini if not set
static eZSession::setUserID (   $userID)
static

Sets the current userID used by ezpSessionHandlerDB::write() on shutdown.

Since
4.1
Parameters
int$userIDto use in ezpSessionHandlerDB::write()

Referenced by eZUser\instance(), eZUser\logoutCurrent(), ezpSessionHandlerDB\read(), and eZUser\setCurrentlyLoggedInUser().

static eZSession::start (   $cookieTimeout = false)
static

Starts the session and sets the timeout of the session cookie.

Multiple calls will be ignored unless you call eZSession::stop() first.

Since
4.1
Parameters
int | false$cookieTimeoutUse this to set custom cookie timeout.
Returns
bool Depending on if session was started.

Referenced by eZScript\initialize().

static eZSession::stop ( )
static

Writes session data and stops the session, if not already stopped.

Since
4.1
Returns
bool Depending on if session was stopped.
static eZSession::triggerCallback (   $type,
  $params 
)
static

Triggers callback functions by type, registrated by eZSession::addCallback() Use: eZSession::triggerCallback('gc_pre', array( $db, $time ) );.

Since
4.1
Parameters
string$typecleanup, gc, destroy, insert and update, pre and post types.
array$paramslist of parameters to pass to the callback function.
Returns
bool

Referenced by ezpSessionHandlerPHP\cleanup(), ezpSessionHandlerDB\cleanup(), ezpSessionHandlerDB\destroy(), ezpSessionHandlerPHP\gc(), ezpSessionHandlerDB\gc(), ezpSessionHandlerPHP\regenerate(), and ezpSessionHandlerDB\regenerate().

static eZSession::unsetkey (   $key,
  $forceStart = true 
)
static

unset session value (wrapper)

Since
4.4
Parameters
string$key
bool$forceStartForce session start if true
Returns
bool|null True if value was removed, false if it did not exist and null if session is not started and $forceStart is false

Referenced by eZHTTPTool\removeSessionVariable().

static eZSession::userHasSessionCookie ( )
static

Returns if user had session cookie at start of request or not.

Since
4.1
Returns
bool|null Null if session is not started yet.
static eZSession::userID ( )
static

Gets the current user id.

Since
4.1
Returns
int User id stored by eZSession::setUserID()

Referenced by ezpSessionHandlerPHP\regenerate(), ezpSessionHandlerDB\regenerate(), and ezpSessionHandlerDB\write().

static eZSession::userSessionIsValid ( )
static

Returns if user session validated against stored data in db or if it was invalidated during the current request.

Since
4.1
Deprecated:
as of 4.4, only returns true for bc
Returns
bool|null Null if user is not validated yet (for instance a new session).

Member Data Documentation

eZSession::$callbackFunctions = array()
staticprotected
eZSession::$handlerInstance = null
staticprotected
eZSession::$hasSessionCookie = null
staticprotected
eZSession::$hasStarted = false
staticprotected
eZSession::$userID = 0
staticprotected

Referenced by setUserID().


The documentation for this class was generated from the following file: