0

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.

0

2 Answers 2

1

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(); 
Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

Thank you for your reply. Unfortunately this solution could not solve the problem. There is no problem with session creation. Because after each session creation session file appears to be created in session folder, but it behaves as if site session does not exist. (There seems to be no problem with folder permissions.)
Were you able to solve this? I'm having the same issue.
Yeah. 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(); `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.