Skip to content

Instantly share code, notes, and snippets.

@jblac
Created January 8, 2013 01:53
Show Gist options
  • Save jblac/4480401 to your computer and use it in GitHub Desktop.
Save jblac/4480401 to your computer and use it in GitHub Desktop.
<?php
class BM_Controller extends CI_Controller {
function __construct() {
parent::__construct();
$logged = $this->check_login();
$cArray = array('login', 'logout');
$this->load->helper('url');
if ($logged == 0 && !in_array($this->uri->segment(1), $cArray) && !in_array($this->uri->segment(2), $cArray)) {
redirect('/login');
}
}
function check_login() {
$logged_in = 0;
$user = $this->session->userdata('user');
if (isset($user)) {
if ($user['intime'] > time() - 3600) {
$user['intime'] = time();
$this->session->set_userdata('user', $user);
$logged_in = 1;
} else {
$this->session->unset_userdata('user');
$logged_in = 0;
}
}
return $logged_in;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment