i got an error session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent

14 Views Asked by At

my error A PHP Error was encountered Severity: Warning

Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: C:\xampp\htdocs\sipaling\application\controllers\Login.php Line: 6 Function: __construct

File: C:\xampp\htdocs\sipaling\index.php Line: 315 Function: require_once

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('session');
    }

    public function index() {
    
        if ($this->session->userdata('login_user') == true) {
            header('Location: '.base_url('dashboard'));
        }else{
            $this->load->view('login');
        }
        
    }
    
    public function proses_session() {
        $data_user = $this->input->post('data_user');
        
        $data_user['login_user'] = true;
    
        $this->session->set_userdata($data_user);
        
        $result = array(
            'status' => 1,
            'message' => 'Selamat Datang '.$data_user['nama'],
        );
        
        echo json_encode($result);
    }
    
    public function logout() {
        $this->session->sess_destroy();
        
        $result = array(
            'status' => 1,
            'message' => 'Berhasil Logout',
        );
        
        echo json_encode($result);
    }
    
}
0

There are 0 best solutions below