|
eZ Publish
[4.2]
|
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(). | |
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 )
| $db | The database object used by the session manager. |
| $key | The session key which are being worked on, see also $escapedKey |
| $escapedKey | The same key as $key but is escaped correctly for the database. Use this to save a call to eZDBInterface::escapeString() |
| $expirationTime | An integer specifying the timestamp of when the session will expire. |
| $expiredTime | Similar 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.
| 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 );
| string | $type | cleanup, gc, destroy, insert and update, pre and post types. |
| handler | $callback | a 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.
Definition at line 162 of file ezsession.php.
| static eZSession::countActive | ( | ) | [static] |
Counts the number of active session and returns it.
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().
| 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
| string | $ip | IPv4 or IPv6 format |
| int | $parts | number from 0-4 |
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').
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
| string | $sessionId | |
| bool | $isCurrentUserSession |
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
| string | $sessionId | |
| string | $value | session data (in php session data format) |
| bool | $isCurrentUserSession |
Definition at line 254 of file ezsession.php.
Referenced by write().
| static eZSession::open | ( | ) | [static] |
Does nothing, eZDB will open connection when needed.
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.
| string | $sessionId |
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()
| bool | $updateUserSession | set to false to not update session in db with new session id and user id. |
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!
Definition at line 386 of file ezsession.php.
Referenced by start().
| static eZSession::remove | ( | ) | [static] |
Removes the current session and resets session variables.
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.
| int | $userID | to 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.
| bool | int | $cookieTimeout | use this to set custom cookie timeout. |
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.
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 ) );.
| string | $type | cleanup, gc, destroy, insert and update, pre and post types. |
| array | $params | list of parameters to pass to the callback function. |
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.
Definition at line 649 of file ezsession.php.
| static eZSession::userID | ( | ) | [static] |
Gets the current user id.
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.
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.
| string | $sessionId | |
| string | $value | session data (in php session data format) |
Definition at line 238 of file ezsession.php.
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.