forked from bcit-ci/CodeIgniter
-
Notifications
You must be signed in to change notification settings - Fork 0
NDB Session Class
Molchy edited this page Sep 8, 2012
·
37 revisions
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. Saving user session data into database is more secure on any type of hosting (Shared ... ). \ This library overwrites normal native sassion functions too save user data directly into database and gives us some extra functions over CI Session.
- Is based on Native Session but has database functionality built in.
- Compatible with CodeIgniter 1.7 +.
- Drop-in replacement for CI’s Session library.
- Config options and flash data are supported but not session encryption.
- When using with a database, only the session_id is stored in a cookie. Any other data is stored in the database (Nativly would be stored to server /tmp ).
- Tested IE6, IE7, IE8, IE9, Firefox 4, Chrome
- PHP5+
- Support the developer and u may see more stuff coming
- PayPal Support and Verified
- Write and Access session data from database:
$_SESSION['Data'] = 'Value'; // Access, same as $this->session->userdata('Data');
$_SESSION['Data]; // Write, same as $this->session->set_userdata('Data', 'Value');
- Get User Online Count:
$count = $this->session->users_online(300); // Returns all user which are or were active in last 5 min
- Parsing session data:
// Enable us to access any session data and manage it, usefull for session management system
// We just past session data from database into session parse function and parse function will return session data in array style so we can access it
$arr_data = $this->session->parse($session_data);
$some_val = $arry_data['session_key'];
- Download Session Class and copy it to "appliaction/libraries/"
- Insert new database table for Session storage
- Autoload or load CI database Class and Session Class
- Don't forget to setup database configuration
- Have fun
- Using native PHP Session functions ( Smaller lib. same security )
- No encryption of cookie as only Session ID is stored in cookie (Allready hashed)
- Checking valid Session ID differently ( We dont save IP, Useragent and Activity in cookie)
- Session garbage collector works differently ( Expired data, Useless data)
- After session destroy we create new empty session so u can set new Session data after it
- Some CI Session functions removed as not needet (Functions which PHP does it for us)
- Extras for setting and accessing Session data( $_SESSION['data'] ...)
CREATE TABLE IF NOT EXISTS `Sessions` (
`sess_id` VARCHAR(40) NOT NULL ,
`sess_ip` VARCHAR(16) NOT NULL ,
`sess_user_agent` VARCHAR(120) NOT NULL ,
`sess_date_activity` DATETIME NOT NULL ,
`sess_date_expire` DATETIME NOT NULL ,
`sess_date_expire_id` DATETIME NOT NULL ,
`sess_data` TEXT NOT NULL ,
PRIMARY KEY (`sess_id`) )
ENGINE = InnoDB
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 3600; // 1 H
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'Sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 600; // 10 min
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
- From 2.1 to 2.12 - Fixed agent issue
- From 2.0 to 2.1 - Change database structure and Session Class
If any issues, mistakes or bugs report them on BitBucket ...
Copyright 2011 - 2012 by Denis Molan. All Rights Reserved