-
Notifications
You must be signed in to change notification settings - Fork 0
NG Session
Code Igniter bundles a session class, working with cookies and limited database support in version 1.6. Unfortunately, this class stores session userdata directly inside the cookie, even using the database.
[h2]Overview[/h2]
- Based on a combination of Codeignitors Session.php in version 1.6 and DBSession.
- Fully compatible with Codeignitors Session.php in version 1.54 and 1.6 and DBSession.
- Designed as drop-in replacement for CI Session and/or DBSession.
- Any config option like encryption and any functionallity like flash session variables are fully supported.
- When using a database, only the session_id is stored in a cookie. Any other data is stored in the database.
- When using without a database, all data is stored in a cookie.
- Both modi work fully tansparent.
[h2]Download[/h2] File:NGSession.zip
[h2]Required database structure[/h2]
Example Mysql:
[code]
CREATE TABLE ci_sessions
(
session_id
varchar(40) NOT NULL default '0',
ip_address
varchar(16) NOT NULL default '0',
user_agent
varchar(50) NOT NULL,
last_activity
int(10) unsigned NOT NULL default '0',
session_data
text,
PRIMARY KEY (session_id
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
[/code]
Note:
- The table is similar to the orginal CI session table definition, execpt that it adds a field session_data to keep userdata and flash variables.
- When using DBSession, the table is pretty much the same. So NGSession will not require any additional database config.
- UTF8 is not necessary but recommanded.
- Of cause, the database library must be loaded.
Example controller: [code] class Main extends Controller {
function Main()
{
parent::Controller();
$this->load->library('view');
// this starts a session if none exists
$this->load->library('session');
}
[/code] Now the session data can be set/get like: [code] if (!$this->session->userdata('user_id')) {} [/code]
[code] set_userdata($newdata = array(), $newval = '') unset_userdata($newdata = array()) all_userdata()set_flashdata($newdata = array(), $newval = '') keep_flashdata($key) flashdata($key) [/code] See the codeignitor documentation for more details.
Pls visit the codeignitor forum