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

Category:Session Native Session makes good use of PHP's native session handling abilities, but it does not allow the use of a database for session storage. KNDB Session is a hybrid which is based upon Native Session but allows use of databases via PHP's ability to store sessions in a DB.

[h2]Overview[/h2]

  • KNDB Session is based on a Native Session but has database functionality built in.
  • Should be compatible with Codeignitor version 1.54 and 1.6.
  • Designed as drop-in replacement for CI's bundled session library.
  • Config options (like encryption) and functionality (like flash data) are supported.
  • When using with a database, only the session_id is stored in a cookie. Any other data is stored in the database.
  • When using without a database, only the session_id is stored in a cookie. Any other data is stored in a file on the server (as PHP does natively).

[h2]Differences between KNDB Session and Native Session[/h2]

  • Allows use of a database for session storage
  • Keeps track of both sess_expiration and sess_time_to_update (in config) and thus distinguishes between session id needing regeneration and the session actually expiring (Native session considered sess_expiration as the time needed to regenerate a session id and never expires the session)
  • Added method all_userdata() to get all session data: this method is in CI's bundled session library but missing from Native Session
  • Made some changes to regenerate_id() method to shorten code and a fix potential bug there

[h2]Required Database Structure[/h2] [code] CREATE TABLE sessions (
session_id varchar(32) NOT NULL,
session_last_access int(10) unsigned,
session_data text,
PRIMARY KEY (session_id)
); [/code]

[h2]Example Configuration (/system/application/config/config.php)[/h2] [code] $config['sess_cookie_name'] = 'CISESSION'; $config['sess_expiration'] = 7200; $config['sess_encrypt_cookie'] = FALSE; $config['sess_table_name'] = 'sessions'; $config['sess_match_ip'] = TRUE; $config['sess_match_useragent'] = TRUE; $config['sess_use_database'] = TRUE; $config['sess_time_to_update'] = 300; [/code]

[h2]Usage[/h2]

  • Place the code in a file named Session.php in your /system/application/libraries/ directory.
  • Use this lib as if you would CI's bundled session library.

[h2]Code[/h2] [code] Coming shortly... [/code]

Clone this wiki locally