Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

505
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda