Welcome Guest, Not a member yet? Register   Sign In
session data issues
#2

[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


Messages In This Thread
session data issues - by El Forum - 11-14-2012, 02:11 PM
session data issues - by El Forum - 11-14-2012, 03:17 PM
session data issues - by El Forum - 11-15-2012, 03:00 PM
session data issues - by El Forum - 11-15-2012, 03:25 PM
session data issues - by El Forum - 11-15-2012, 03:53 PM
session data issues - by El Forum - 11-15-2012, 06:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB