Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 13 revisions

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.

[h3] Benefits over CI_Session and DB_Session[/h3]

  • 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.

[h3] Usage [/h3]

  • 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()

[h3] Configuration [/h3] The original config entry for CI session is amended as follows: [code]

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;

[/code] [h3]Modifications of original CI implementation [/h3] 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.

[h3]Discussion, Documentation and download[/h3]

  • For general usage, please see the CI session documentation [url=http://www.codeigniter.com/user_guide/libraries/sessions.html]user_guide[/url]
  • For specific usages, please see the OB Session documentation online [url=http://bleakview.orgfree.com/obsession/]OB Session[/url]
  • To discuss, post questions or bug reports please see thread [url=http://codeigniter.com/forums/viewthread/49253/]Discussion thread[/url]
  • You can download the library, documentation and demo / test code here [url=http://bleakview.orgfree.com/dl/obsession.zip]obsession.zip[/url]
Clone this wiki locally