SessionManager

PHP itself provides session management. For this reason the super global variable $_SESSION is used to store the session data and several functions allow to start, create or delete a session. To have a tool for transparent session management some more code must be added to use the session commonly within several program parts. This issue is solved by the SessionManager of the Adventure PHP Framework. If a session is needed within an application the session manager can be initialized by
PHP code
$sessMgr = new SessionManager('{ApplikationsNamespace}');
"{ApplikationsNamespace}" thereby describes the namespace of the session, that should be used in further code parts. Commonly the namespace is filled with the namespace of the current application to indicate affiliation. To be able to use the session manager it must be imported using the directive
PHP code
import('core::session','SessionManager');
The SessionManager partitions the session provided by PHP natively into different namespaces in order to use on PHP session multiple times by Adventure PHP Framework applications at the same time.
PHP code
$sessMgr->saveSessionData('MyParam','MyValue');
makes it able to store data in the session namespace defined by instanciating the session manager. Besides, the SessionManager makes sure that the session is always existent while using it in an application. session_start() is not necessary any more. Data stored in a session namespace can easily gathered by
PHP code
echo $sessMgr->loadSessionData('MyParam');
The data displayed in this example is read from the namespace the session manager was initialized with. To initiate a logout procedure all data within a specific namespace can be deleted by
PHP code
$sessMgr->destroySession();
Afterwards calling loadSessionData() returns null.

Calling

PHP code
$sessMgr->loadAllSessionData();

returns an associative array including all entries registered in the session namespace given when creating the session manager. In case you only need a list of keys registered within the session, you can call

PHP code
$sessMgr->getEntryDataKeys();

Comments

Do you want to add a comment to the article above, or do you want to post additional hints? So please click here. Comments already posted can be found below.
There are no comments belonging to this article.