Tuesday, 27 August 2013

unable to use session variable

unable to use session variable

I'm using a codeigniter and i have 3 controller, i use the session to
store username from the 1st controller and i use this to determine from
the other controller if someone is logged in.
Here is a the constructor of the first controller, in this class, i also
use the statement where i give a value to $_SESSION['username'] so the
other controller use it:
class Login extends CI_Controller {
public function __construct()
{
session_start();
parent::__construct();
}
This is the 2nd controller, on he constructor, i created a conditional
statement to determine if someone is logged in, i tested this and it's
still ok:
class Pagination extends CI_Controller {
public function __construct() {
parent:: __construct();
$this->load->helper("url");
session_start();
if(!isset($_SESSION['username'])){
redirect(base_url().'index.php/login');
}
}
In the 3rd controller, this is where i encounter the problem, i cannot
access the variable where i stored the username, here is the code:
class Blood_Controller extends CI_Controller {
public function __construct()
{
session_start();
parent::__construct();
if(!isset($_SESSION['username'])){
redirect(base_url().'index.php/login');
}
}
It always go inside the if statement even if i enter a rightusername on
the 1st controller. can anyone help?

No comments:

Post a Comment