class CI_Controller {
/**
* Reference to the CI singleton
*
* @var object
*/
private static $instance;
public $need_login = TRUE;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
$this->load =& load_class('Loader', 'core');
$this->load->initialize();
log_message('info', 'Controller Class Initialized');
$this->check_login();
}
// --------------------------------------------------------------------
/**
* Get the CI singleton
*
* @static
* @return object
*/
public static function &get_instance()
{
return self::$instance;
}
public function check_login()
{
if($this->need_login)
{
$this->load->library('session');
// echo isset($_SESSION['user']);
if( ! isset($_SESSION['user']) || $_SESSION['user'] == NULL )
{
$this->session->set_userdata('user', NULL);
$url = '/index.php/Home';
echo '<script language="javascript" type="text/javascript">';
echo 'window.location.href="' . $url . '"';
echo '</script>';
exit;
}
}
}
}
/index.php/home 是用来登录的, session保存用户名。