eZ Publish  [4.2]
eZSession Class Reference

List of all members.

Static Public Member Functions

static addCallback ($type, $callback)
 Adds a callback function, to be triggered by eZSession::triggerCallback() when a certan session event occurs.
static cleanup ()
 Truncates all session data in the database.
static close ()
 Does nothing, eZDB will handle closing db connection.
static countActive ()
 Counts the number of active session and returns it.
static destroy ($sessionId)
 Deletes the session data from the database, this function is register in eZSession::registerFunctions().
static garbageCollector ()
 Deletes all expired session data in the database, this function is register in eZSession::registerFunctions().
static getUserSessionHash ()
 Gets/generates the user hash for use in validating the session based on [Session] SessionValidation* site.ini settings.
static internalRead ($sessionId, $isCurrentUserSession=true)
 Internal function that reads the session data from the database, this function is registered as session_read handler in eZSession::registerFunctions() Note: user will be "kicked out" as in get a new session id if self::getUserSessionHash() does not equals to the existing user_hash unless the user_hash is empty.
static internalWrite ($sessionId, $value, $isCurrentUserSession=true)
 Internal function that inserts|updates the session data in the database, this function is registered as session_write handler in eZSession::registerFunctions().
static open ()
 Does nothing, eZDB will open connection when needed.
static read ($sessionId)
 Reads the session data from the database for a specific session id.
static regenerate ($updateUserDBSession=true)
 Will make sure the user gets a new session ID while keepin the session data.
static remove ()
 Removes the current session and resets session variables.
static setUserID ($userID)
 Sets the current userID used by self::write on shutdown.
static start ($cookieTimeout=false)
 Starts the session and sets the timeout of the session cookie.
static stop ()
 Writes session data and stops the session, if not already stopped.
static triggerCallback ($type, $params)
 Triggers callback functions by type, registrated by eZSession::addCallback() Use: eZSession::triggerCallback('gc_pre', array( $db, $time ) );.
static userHasSessionCookie ()
 Returns if user had session cookie at start of request or not.
static userID ()
 Gets the current user id.
static userSessionIsValid ()
 Returns if user session validated against stored data in db or if it was invalidated during the current request.
static write ($sessionId, $value)
 Inserts|Updates the session data in the database for a specific session id.

Public Attributes

const HANDLER_NAME = 'ezdb'

Protected Member Functions

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

Static Protected Member Functions

static getIpPart ($ip, $parts=2)
 Gets part of a ipv4/ipv6 address, used internally by eZSession::getUserSessionHash().
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.

Static Protected Attributes

static $callbackFunctions = array()
 List of callback actions, see eZSession::addCallback().
static $hasSessionCookie = null
 Flag request contains session cookie, set in eZSession::registerFunctions().
static $hasStarted = false
 Flag session started, see eZSession::start().
static $userID = 0
 User id, see eZSession::userID().
static $userSessionHash = null
 User session hash (ip + ua string), set in eZSession::registerFunctions().
static $userSessionIsValid = null
 Flag if user session validated when reading data from session, set in eZSession::internalRead().

Detailed Description

Re-implementation of PHP session management using database.

The session system has a hook system which allows external code to perform extra tasks before and after a certain action is executed. For instance to cleanup a table when sessions are removed. This can be used by adding a callback with the eZSession::addCallback function, first param is type and second is callback (called with call_user_func_array)

  function cleanupStuff( $db, $key, $escKey )
  {
      // Do cleanup here
  }

  eZSession::addCallback( 'destroy_pre', 'cleanupstuff');
  // Or if it was a class function:
  // eZSession::addCallback( 'destroy_pre', array('myClass', 'myCleanupStuff') );

When new data is inserted to the database it will call the update_pre and update_post hooks. The signature of the function is function insert( $db, $key, $escapedKey, $expirationTime, $userID, $value )

When existing data is updated in the databbase it will call the insert_pre and insert_post hook. The signature of the function is function update( $db, $key, $escapedKey, $expirationTime, $userID, $value )

When a specific session is destroyed in the database it will call the destroy_pre and destroy_post hooks. The signature of the function is function destroy( $db, $key, $escapedKey )

When multiple sessions are expired (garbage collector) in the database it will call the gc_pre and gc_post hooks. The signature of the function is function gcollect( $db, $expiredTime )

When all sessionss are removed from the database it will call the cleanup_pre and cleanup_post hooks. The signature of the function is function cleanup( $db )

Parameters:
$dbThe database object used by the session manager.
$keyThe session key which are being worked on, see also $escapedKey
$escapedKeyThe same key as $key but is escaped correctly for the database. Use this to save a call to eZDBInterface::escapeString()
$expirationTimeAn integer specifying the timestamp of when the session will expire.
$expiredTimeSimilar to $expirationTime but is the time used to figure if a session is expired in the database. ie. all sessions with lower expiration times will be removed.

Definition at line 83 of file ezsession.php.


Member Function Documentation

static eZSession::addCallback ( type,
callback 
) [static]

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

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

Parameters:
string$typecleanup, gc, destroy, insert and update, pre and post types.
handler$callbacka function to call.

Definition at line 681 of file ezsession.php.

static eZSession::cleanup ( ) [static]

Truncates all session data in the database.

Named eZSessionEmpty() in eZ Publish 4.0 and earlier!

Definition at line 353 of file ezsession.php.

static eZSession::close ( ) [static]

Does nothing, eZDB will handle closing db connection.

Returns:
true

Definition at line 162 of file ezsession.php.

static eZSession::countActive ( ) [static]

Counts the number of active session and returns it.

Returns:
string Returns number of sessions.

Definition at line 370 of file ezsession.php.

static eZSession::destroy ( sessionId) [static]

Deletes the session data from the database, this function is register in eZSession::registerFunctions().

Parameters:
string$sessionId

Definition at line 317 of file ezsession.php.

eZSession::eZSession ( ) [protected]

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

protected

Definition at line 141 of file ezsession.php.

static eZSession::garbageCollector ( ) [static]

Deletes all expired session data in the database, this function is register in eZSession::registerFunctions().

Definition at line 335 of file ezsession.php.

static eZSession::getIpPart ( ip,
parts = 2 
) [static, protected]

Gets part of a ipv4/ipv6 address, used internally by eZSession::getUserSessionHash().

protected

Parameters:
string$ipIPv4 or IPv6 format
int$partsnumber from 0-4
Returns:
string returns part of a ip imploded with '-' for use as a hash.

Definition at line 519 of file ezsession.php.

Referenced by getUserSessionHash().

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').

Returns:
string Returns md5 hash based on parts of the user ip and agent string.

Definition at line 484 of file ezsession.php.

static eZSession::internalRead ( sessionId,
isCurrentUserSession = true 
) [static]

Internal function that reads the session data from the database, this function is registered as session_read handler in eZSession::registerFunctions() Note: user will be "kicked out" as in get a new session id if self::getUserSessionHash() does not equals to the existing user_hash unless the user_hash is empty.

private

Parameters:
string$sessionId
bool$isCurrentUserSession
Returns:
string|false Returns false if session doesn't exits

Definition at line 191 of file ezsession.php.

Referenced by read().

static eZSession::internalWrite ( sessionId,
value,
isCurrentUserSession = true 
) [static]

Internal function that inserts|updates the session data in the database, this function is registered as session_write handler in eZSession::registerFunctions().

private

Parameters:
string$sessionId
string$valuesession data (in php session data format)
bool$isCurrentUserSession
Returns:
bool

Definition at line 254 of file ezsession.php.

Referenced by write().

static eZSession::open ( ) [static]

Does nothing, eZDB will open connection when needed.

Returns:
true

Definition at line 151 of file ezsession.php.

static eZSession::read ( sessionId) [static]

Reads the session data from the database for a specific session id.

Parameters:
string$sessionId
Returns:
string|false Returns false if session doesn't exits, string in php session format if it does.

Definition at line 174 of file ezsession.php.

static eZSession::regenerate ( updateUserDBSession = 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()

Parameters:
bool$updateUserSessionset to false to not update session in db with new session id and user id.
Returns:
bool Returns true|false depending on if session was regenerated.

Definition at line 557 of file ezsession.php.

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

static eZSession::registerFunctions ( ) [static, protected]

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

Named eZRegisterSessionFunctions() in eZ Publish 4.0 and earlier!

Returns:
bool Returns true|false depending on if eZSession is registrated as session handler.

Definition at line 386 of file ezsession.php.

Referenced by start().

static eZSession::remove ( ) [static]

Removes the current session and resets session variables.

Returns:
bool Returns true|false depending on if session was removed.

Definition at line 604 of file ezsession.php.

Referenced by eZScript\shutdown().

static eZSession::setUserID ( userID) [static]

Sets the current userID used by self::write on shutdown.

Parameters:
int$userIDto use in eZSession::write()

Definition at line 627 of file ezsession.php.

Referenced by eZUser\instance(), eZUser\logoutCurrent(), 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.

Parameters:
bool | int$cookieTimeoutuse this to set custom cookie timeout.
Returns:
bool Returns true|false depending on if session was started.

Definition at line 444 of file ezsession.php.

Referenced by eZSessionStart(), eZScript\initialize(), and eZHTTPTool\instance().

static eZSession::stop ( ) [static]

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

Returns:
bool Returns true|false depending on if session was stopped.

Definition at line 532 of file ezsession.php.

static eZSession::triggerCallback ( type,
params 
) [static]

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

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

Definition at line 699 of file ezsession.php.

Referenced by cleanup(), destroy(), garbageCollector(), internalWrite(), and regenerate().

static eZSession::userHasSessionCookie ( ) [static]

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

Returns:
bool|null returns null if session is not started yet.

Definition at line 649 of file ezsession.php.

static eZSession::userID ( ) [static]

Gets the current user id.

Returns:
int Returns user id stored by eZSession::setUserID()

Definition at line 638 of file ezsession.php.

static eZSession::userSessionIsValid ( ) [static]

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

Returns:
bool|null returns null if user is not validated yet (for instance a new session).

Definition at line 661 of file ezsession.php.

static eZSession::write ( sessionId,
value 
) [static]

Inserts|Updates the session data in the database for a specific session id.

Parameters:
string$sessionId
string$valuesession data (in php session data format)

Definition at line 238 of file ezsession.php.


Member Data Documentation

eZSession::$callbackFunctions = array() [static, protected]

List of callback actions, see eZSession::addCallback().

protected

Definition at line 134 of file ezsession.php.

eZSession::$hasSessionCookie = null [static, protected]

Flag request contains session cookie, set in eZSession::registerFunctions().

protected

Definition at line 110 of file ezsession.php.

Referenced by userHasSessionCookie().

eZSession::$hasStarted = false [static, protected]

Flag session started, see eZSession::start().

protected

Definition at line 102 of file ezsession.php.

eZSession::$userID = 0 [static, protected]

User id, see eZSession::userID().

protected

Definition at line 94 of file ezsession.php.

Referenced by internalWrite(), setUserID(), and userID().

eZSession::$userSessionHash = null [static, protected]

User session hash (ip + ua string), set in eZSession::registerFunctions().

protected

Definition at line 126 of file ezsession.php.

Referenced by getUserSessionHash().

eZSession::$userSessionIsValid = null [static, protected]

Flag if user session validated when reading data from session, set in eZSession::internalRead().

protected

Definition at line 118 of file ezsession.php.

Referenced by userSessionIsValid().

const eZSession::HANDLER_NAME = 'ezdb'

Definition at line 86 of file ezsession.php.


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