I can't save my custom session on database with codeigniter and i don't know why.
This is my config.php
$config['encryption_key'] = 'MY_KEY';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
And in my Model i have this:
foreach ($res as $user) {
$usuario["name"] = $user->name;
$usuario["lastname"] = $user->lastname;
$usuario["date_birthday"] = $user->date_birthday;
$usuario["date_register"] = $user->date_register;
$usuario["last_season"] = $user->last_seasson;
$usuario["email"] = $user->email;
$usuario["contry"] = $user->contry;
$usuario["sex"] = $user->sex;
$usuario["role"] = $user->role;
$usuario["status"] = $user->status;
$usuario["idUsuario"] = $user->id;
}
$this->set_last_season($usuario["idUsuario"]);
$this->session->set_userdata('usuario', $usuario);
And in my Controller, I try view my session with:
var_dump($this->session->userdata('usuario'));
And I created my session table in database with:
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`)
);
All this code works fine without saving session on database and using cookie sessions
Please, i need help.... i don't know that try more... Thanks for all
Well I followed exhaustively analyzing the flow of my application, and I detected the fault came in the redirect from the login controller to any other controller. At that time, was losing the sessiones codeigniter.
I was documenting this failure, and saw that there were very many more people affected and did not believe that this ruling embers unresolved. So here after searching thoroughly in Google, I found an interesting article that was describing this problem and provided a "patch" for the Sessions library files included in codeigniter system.
This library I did was to reuse all the methods of the original library but applying it to a use of native sessiones. Thus the passage of sessiones between controllers did not fail.
What if someone else has had the same problem, or for future developers who have left the link in the article which is the code of the new library session.