Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

498
Views
Session variables not working codeigniter (PHP)

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.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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(); 
over 4 years ago · Santiago Trujillo Report

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!