0

I'm building a Codeigniter application with ION Auth, which is going relatively OK. I've set up the ION Auth framework following this guide http://www.rappasoft.com/tutorials/5-building-a-simple-codeigniter-application-using-ion-auth.html#.U0Q5ufldUrU and when I log in using the default username and password I'm redirect to my homepage. So far, so good.

Problem then is that when I access one of my protected pages (i.e. a controller which extends MY_Controller), I'm redirected to the login page again.

I'm quite new to this, so just looking for some pointers of where to look. It seems I'm being logged in, but I don't really know how to check for sure.

I've tried this line of code in my view, but I get a couple of errors: user_info is undefined & trying to get property of a non object.

<?php echo $user_info->username;?>

MY_Controller in application/core:

 if ( ! defined('BASEPATH')) exit('No direct script access allowed');  

class MY_Controller extends CI_Controller {

public function __construct() {
   parent::__construct();

   if (!$this->ion_auth->logged_in()) {
        redirect('auth/login');
   } else {
        //Store user in $data
        $data->user_info = $this->ion_auth->user()->row();
        //Load $the_user in all views
        $this->load->vars($data);        
   }
}
}

My 'members only' area controller class declaration:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Manage extends MY_Controller {

    function __construct()
    {
        parent::__construct();

        $this->load->database();
        $this->load->library('grocery_CRUD'); 
    }
//other functions omitted
gazrolo4
  • 161
  • 2
  • 17

1 Answers1

0

Add this to your MY_Controller and see what is returned

var_dump($this->ion_auth->logged_in());exit;
Ben Edmunds
  • 888
  • 4
  • 6
  • Hi @Ben-Edmunds - help from the top, thanks! I modified my controller above by adding the line above before the if/else block, then logged in, which took me to my home page, but nothing was echoed. However, my homepage doesn't extend `MY_Controller`, so I guess I need this code on one of the pages that does. Problem is, I get redirected from those pages as I'm not logged in! Any pointers on what to try next? Guess I could turn off the redirect if `(!logged_in())` and then see what I get echoed on one of `MY_Controller` pages? At work currently so will try in a few hours. Thanks :-) – gazrolo4 Apr 09 '14 at 08:16
  • Just comment out the redirect for now and see what happens. – Ben Edmunds Apr 09 '14 at 21:01
  • Hey Ben, commented out the redirect on `MY_Controller`, logged in and accessed a MY_Controller page. `logged_in()` is echoing false...so clearly I've got something going wrong in my login process. A while back I set up encryption in the CI config file and a ci_sessions table in the DB...was really just experimenting...could this be anything to do with it? – gazrolo4 Apr 10 '14 at 21:26