Category:Libraries -> Session
Category:Session
An attempt to provide the best of all possible session worlds.
This replacement class for Code Igniter session library borrows from ideas presented in Native session and DB Session.
It attempts to retain all the benefits of the original CI implementation, adding the best features from other libs and adds several enhancements.
Benefits over CI_Session and DB_Session
* Session User Data can be stored either client-side in the cookie OR server-side in a database table.
* Highly configurable:
* Easily configure non-persistent sessions, session timeouts and session auto regeneration. (A non-persistent session ends on browser exit.)
* Incorporates “Flash data” as implemented in Native_Session and DB_Session.
* Provides function for manual session id regeneration.
Usage
* the same as the original CI session library - just load the library from your /application/libraries directory : $this->load->library(‘session’);
* access the session data via : $this->session->userdata() and $this->session->set_userdata() methods.
* Allows regenerating the session id manually by calling session->regenerate_id()
Configuration
The original config entry for CI session is amended as follows:
| Session Variables
|--------------------------------------------------------------------------
|
| 'session_cookie_name' = the name you want for the cookie
| 'encrypt_sess_cookie' = TRUE/FALSE (boolean). Whether to encrypt the cookie
| 'session_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours).
| Set to zero (0) for a session which expires on browser exit.
|---------------------------------
| Additional config items:
| 'sess_storage' = Store USER DATA in 'cookie' or 'database'
| Some session data is always stored in the cookie, prefixed with "session_"
| Viz: "session_id", "session_start", "session_last_activity", "session_ip_address", "session_user_agent".
| 'sess_timeout' = session time-to-live, in seconds, set to zero for no timeout.
| 'sess_destroy_on_timeout' = TRUE/FALSE (boolean)
| The default is FALSE, the session_id is regenerated and existing session data is saved.
| 'sess_update_interval' = Period in SECONDS between session updates.
|
*/
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
// [OB] additional config items:
$config['sess_storage'] = 'cookie';
$config['sess_timeout'] = 0;
$config['sess_destroy_on_timeout'] = FALSE;
$config['sess_update_interval'] = 300;
Modifications of original CI implementation
The session variable “last_visit” is removed and replaced with “session_start”
Be aware that some session data is always present in the session cookie.
* session_id
* session_start
* session_last_activity
* session_ip
* session_user_agent
Please enable cookie encryption if you do not want this info to be visible.
Discussion, Documentation and download
* For general usage, please see the CI session documentation user_guide
* For specific usages, please see the OB Session documentation online OB Session
* To discuss, post questions or bug reports please see thread
Discussion thread
* You can download the library, documentation and demo / test code here obsession.zip
