I create simple library called Xauth.php to check if user already login or not:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Xauth
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public function is_logged_in()
{
if ($this->ci->session->userdata('is_logged_in'))
{
return true;
}
return false;
}
}
I put that library in my Admin_Controller, so whatever controller extended with Admin_Controller will be checked first, if the session data is empty they will be redirect to login page. And this is my Admin_Controller.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin_Controller extends MY_Controller {
public function __construct()
{
$this->load->library('Xauth');
if ($this->Xauth->is_logged_in() == false) {
redirect('auth');
}
}
}
But I got an errors, it says:
Message: Undefined property: Dashboard::$Xauth
Where is my fault?