Codeigniter session not working in another controller when using xampp Codeigniter session not working in another controller when using xampp codeigniter codeigniter

Codeigniter session not working in another controller when using xampp


You don't need to load the config/config.php file as it's all ready loaded.

Make sure you have set your sessions something like this I my self created a session folder in system so it is more protected. Set the folder permission 0700

$config['sess_driver'] = 'files';$config['sess_cookie_name'] = 'ci_session';$config['sess_expiration'] = 1440;$config['sess_save_path'] = BASEPATH . 'storage/session/'; $config['sess_match_ip'] = TRUE;$config['sess_time_to_update'] = 300;$config['sess_regenerate_destroy'] = TRUE;

Note

EXT: The PHP file extensionFCPATH: Path to the front controller (this file) (root of CI)SELF: The name of THIS file (index.php)BASEPATH: Path to the system folderAPPPATH: The path to the "application" folder

Autoload.php

$autoload['libraries'] = array('session');$autoload['helper'] = array('form', 'url');

Controller

<?php defined('BASEPATH') OR exit('No direct script access allowed');class Test extends CI_Controller {    function __construct() {        parent::__construct();        // Autoload the url helper in config/autoload.php        $this->load->helper("url");    }    function index() {        $newdata = array(            'username' => 'uname',            'email' => 'uname@some-site.com'        );        $this->session->set_userdata('testsession', $newdata);        $session_data = $this->getSession();        $data['username'] = $session_data['username'];        $data['email'] = $session_data['email'];        $this->load->view('test_view', $data);    }    function getSession()    {        return $this->session->userdata('testsession');    }}

Then on the views / test_view.php

<?php echo $username;?><?php echo $email;?>

Using the redirect() https://www.codeigniter.com/user_guide/helpers/url_helper.html#redirect