codeIgnitor will usually make everything work out of the box. However, Sessions are a very sensitive component of any application. Its important for you to understand that once initialized, the Session class runs automatically. There is nothing you need to do to cause the above behavior to happen. You can work with session data, but the process of reading, writing, and updating a session is automatic.
CodeIgnitor gives access to its session data through the same means, as it uses the session handlers mechanism provided by PHP.
Using session data is as simple as manipulating (set and unset values) the global $_SESSION array .
CodeIgniter have relation with database to store session data information. When session data is available in the database. We can access a valid session data every time or every request and also match session ID from user' session cookie. If the session ID does not match then session is destroyed . We can not update session ID, Its created when session is initialized.
If You want to store session into the database you first create a table in database.
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
CodeIgniter by default have name of table ci_sessions ,but you can update name of the table according your requirement. You need to follow the update setting in application/config/config.php by default $config['sess_use_database'] = FALSE, if you want to use database session its need to TRUE and you can use global $config array to change table name $config['sess_table_name'] = 'ci_sessions'.
0 Comment(s)