I'm using Codeigniter to create a student testing system but for some reason my sessions data seems to be acting strangely. On my login page the user selects their username from a pulldown list (I doesn't have to be secure at this stage) this passes the userid of the selected user to a function which sets up the userdata in the session and then redirects them to the dashboard page. Now my problem is this. when the dashboard page is loaded either by using redirect in the url helper or manually by navigating to localhost/progsqs/dashboard, the session class creates a new, blank, session.
I wrote a few small test functions which do the same thing but they work fine one session with retrievable data (which rules out a codeigniter configuration problem) but for reasons unknown dashboard ALWAYS builds a new blank session and tries to work with it. I'm at my wits end and need a fresh pair of eyes to look at it and see the mistake I've obviously made but cannot for the life of me spot.
<?php
class Progsqs extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->login();
}
function login()
{
$this->load->model('Progsq_Model');
$data['users'] = $this->Progsq_Model->getUsers();
$this->load->view('templates/header.php');
$this->load->view('progsqs/login.php', $data);
$this->load->view('templates/footer.php');
}
function logout()
{
$this->load->helper('url');
$this->session->sess_destroy();
redirect(base_url('progsqs/login'));
}
function setUser()
{
$this->load->helper('url');
$this->load->model('Progsq_Model');
$username = $this->Progsq_Model->getUsername($_POST['userlist']);
$this->session->set_userdata('username', $username);
echo $this->session->userdata('username');
//redirect(base_url('progsqs/dashboard'));
}
function dashboard()
{
echo($this->session->userdata('username'));
print_r($this->session->all_userdata());
}
function profile()
{
$this->load->view('templates/header');
$this->load->view('progsqs/profile');
$this->load->view('templates/footer');
}
function testBuilder()
{
}
/*
Debugging code for repairing session data
*/
function inputtest()
{
$this->session->set_userdata('somedata', 'This is a test');
$this->load->helper('url');
redirect(base_url('progsqs/testoutput'));
}
function outputtest2()
{
echo($this->session->userdata('somedata'));
//print_r($this->session->all_userdata());
}
function testoutput()
{
$this->load->model('Progsq_Model', '', TRUE);
$data['users'] = $this->Progsq_Model->getUsers();
$this->load->view('templates/header.php');
$this->load->view('progsqs/outputtest.php', $data);
$this->load->view('templates/footer.php');
}
function killsession()
{
$this->session->sess_destroy();
}
}
?>