What cause the session is recreate or gone after refresh page?
im using codeigniter on my project, and i have a login module and i have
authenticate the each module when the session is not exist then redirect
to the login page. so, this is work but sometimes it may happen when i
login then i refresh the page then i redirect to the login page (means
session is gone!).
Don't try to call me use other library such as php native or etc. i just
want to know what is the problem to cause this happen?
function _admin_login()
{
$this->form_validation->set_rules($this->login_rules);
$data['title'] = "Login";
$data['form_url'] = $this->uri->uri_string();
$data['login_btn'] = form_submit('login','Sign In','class="btn
btn-large btn-block btn-primary"');
if($this->form_validation->run($this) == FALSE){
$data['user'] =
form_input('username','','class="input-block-level
input-large" placeholder="Username"');
$data['passw'] =
form_password('password','','class="input-block-level
input-large" placeholder="Password"');
$this->template->set('title','Login');
$this->template->load('template_login','login_view',$data);
}else{
$username = $this->input->post('username',true);
$row = $this->authentication_model->get_user_info($username);
$this->session->set_userdata('user',$row['user_id']);
$this->session->set_userdata('username',$row['username']);
$this->session->set_userdata('login_state',true);
$this->authentication_model->update_last_login();
redirect('product');
}
}
this is my login script, if validation pass then set the session... and in
every controller i had check the session script. example below
$this->authentication_plugin->check_logged_in();
function check_logged_in()
{
if(logged_in() === FALSE){
set_alert('Login in to view this page!!','error');
set_bookmark('login_url');
redirect("login");
}
}
function logged_in()
{
$CI =& get_instance();
$user = $CI->session->userdata('user');
if(!$CI->load->library('session')){
echo "no session is loaded";
die;
}
if(!empty($user)){
return true;
}else{
return false;
}
}
so any idea? thank~!!
No comments:
Post a Comment