[eluser]adamck[/eluser]
In my Login Script.. i set the following user data.
Login Controller Function
Code:
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
Then in the other controllers i have this
Code:
function index()
{
$this->is_logged_in();
// DO YOUR STUFF HERE, IT WILL ONLY RUN IF THE USER IS LOGGED IN
}
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
// IF USER IS NOT LOGGED IN REDIRECT TO ANOTHER PAGE
if(!isset($is_logged_in) || $is_logged_in != TRUE)
{
redirect('error/not_logged_in');
}
}
If you want an entire controller to only work for logged in users you can put the $is_logged_in function at the bottom and then the the $this->is_logged_in(); can go in the page construct
Code:
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
hope it helps