Membuat Fungsi agar tidak perlu mengecek berkali-kali session login pada fungsi code igniter
class User extends CI_Controller{function __construct(){
parent::__construct();
if (current_url()!=site_url().'/user/login') {
if (!$this->session->userdata('user_logged_in'))
{
redirect(site_url().'/user/login');
}
}
}
function index(){
$isi['title'] = 'Halaman User';
$isi['sidebar_left'] = 'module/user';
$isi['top_menu'] = 'menu/top_menu_user';
$isi['content'] = 'module/user';
$isi['footer'] = 'block/runningtext_login';
$this->load->view('template/user', $isi);
}
function login() {
if ($this->session->userdata('user_logged_in'))
{
redirect(site_url().'/user');
}
$isi['title'] = 'Halaman Login';
$isi['content'] = 'module/login';
$isi['footer'] = 'block/runningtext_login';
$this->load->view('template/login', $isi);
}
function logout(){
$this->session->unset_userdata('user_id');
$this->session->unset_userdata('username');
$this->session->unset_userdata('user_logged_in');
$this->session->unset_userdata('login_time');
$this->session->sess_destroy();
$this->session->set_flashdata('message', 'Logout Sukses');
redirect(site_url().'/user/login');
}
}
0 comments:
You can post comment with english language or indonesia language.
Anda bisa memberikan komentar dalam bahasa inggris atau bahasa indonesia.