[eluser]Ellli[/eluser]
Maybe im stupid, or maybe im just not seeing something but i need help :o)
I have simple method that check if user is logged in:
Code:
public function is_logged(){
$result = $this->session->userdata('is_log');
return (bool) $result;
}
in my controller methods if i need it i call it like that:
Code:
function show(){
if(!$this->model_user->is_logged()){
redirect('admin/user/login');
}else{
//do stuff
}
and it works great when im just moving from page to page (most of them is checking if user is logged). The problem is when i want set flashdata and then redirect.
For example, i have method in cotroller:
Code:
function publish($lvl=0){
if($this->input->post('submited')){
//collecting $data
$stuff = $this->model_pages->update($data);//do stuff, update table
if($stuff){
$this->session->set_flashdata('msg','ok');
}else{
$this->session->set_flashdata('err_msg','not ok');
}
redirect('admin/pages/show/');
}else{ //if access directly without submit
redirect('admin/pages/go/');
}
}
even if i set_flashdata in:
Code:
}else{ //if access directly without submit
$this->session->set_flashdata('err_msg','no direct access allowed!');
redirect('admin/pages/go/');
}
the user is redirect to login form. i happens always when i use set_flashdata and redirect because for some reason this -> if(!$this->model_user->is_logged()){ is always true.
I tried echo result of function is_logged, just before redirect but after set_flashdata and the result is "true"...
To store data after login (if success) im using this method:
Code:
public function login_sess($user){
$data = array(
'username' => $user['nick'],
'user_id' => $user['id'],
'is_log' => TRUE
);
$this->session->set_userdata($data); }
When im not setting any flashdata everything works fine. And i spend all day trying to solve this stupid problem and because of that i dont want to make some workaround.
For my session config, im using database, the domain is ok, config is:
Code:
$config['sess_cookie_name'] = 'cbcms';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
i tried every combination with match ip and useragent.
oh, and in database flashdata is stored, and i can see userdata and session_id is the same before redirect and after.
and if someone wanna ask, session class is in autoload. please please help. its driving me crazy..
ps. and if someone didnt notice CI is something new for me so in this ps i just wanna say hello :o)