Reputation: 11
I have a problem with Session. I have not experienced this problem on localhost or other servers. Only one.com has this problem. The session is defined and set to the specified session folder, but the session appears to be missing when the page is refreshed.
Login Page Code
$submitted = $this->input->post('email');
$admin_logged_in = $this->session->userdata('admin_logged_in');
if($admin_logged_in != true){
if($submitted != ""){
$email = xss_clean($this->input->post('email'));
$password = xss_clean($this->input->post('password'));
$id = $this->Admin_Model->admin_log($email,$password);
if($id == 1){
$user = $this->Admin_Model->get_admin($email);
$data['user'] = $user;
$session_data = array(
'admin_id' => $user->id,
'admin_email' => $user->email,
'admin_logged_in' => true
);
$this->session->set_userdata($session_data);
redirect('admin');
}else{
$data['error'] = array( 'type' => 'error', 'message' => 'Account information is incorrect.');
$this->load->view('admin/login',$data);
}
}else{
$this->load->view('admin/login',$data);
}
}else{
$user_id = $this->session->userdata('admin_id');
$user = $this->Admin_Model->get_admin_id($user_id);
$data['user'] = $user;
$this->load->view('admin/admin_home',$data);
}
İndex Page Code (Next page after login)
$admin_logged_in = $this->session->userdata('admin_logged_in');
if($admin_logged_in == true){
$user_id = $this->session->userdata('admin_id');
$user = $this->Admin_Model->get_admin_id($user_id);
$data['user'] = $user;
$this->load->view('admin/admin_home',$data);
}else{
$this->load->view('admin/login',$data);
}
Session Config
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions'; // Or sys_get_temp_dir()
$config['sess_match_ip'] = FALSE; // Or True
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE; // Or True
I am already grateful to the friends who can find a solution.
Upvotes: 0
Views: 1384
Reputation: 11
I haven't written a reply in a long time but maybe I'il meet the needs of other friends.
$config['sess_driver'] = 'files';
$config['sess_save_path'] = sys_get_temp_dir();
Upvotes: 1
Reputation:
You need to set your session save path something like
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
because you have $config['sess_driver']
as files
Then $autoload['libraries'] = array('session');
Folder permission 0700
EXT: The PHP file extension
FCPATH: Path to the front controller (this file) (root of CI)
SELF: The name of THIS file (index.php)
BASEPATH: Path to the system folder
APPPATH: The path to the "application" folder
Upvotes: 0