Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

499
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda