Advertisement
jamboljack

Set Userdata

Nov 28th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Administrator extends CI_Controller {
  5.     function __construct() {
  6.         parent::__construct();
  7.         $this->load->model('administrator_model');
  8.     }
  9.  
  10.     public function index() {
  11.         $session = $this->session->userdata('logged_in_dagsar');
  12.         if ($session == FALSE) {
  13.             $this->load->view('administrator_view');
  14.         } else {
  15.             redirect(site_url('admin/home'));
  16.         }
  17.     }
  18.  
  19.     public function validasi() {
  20.         $username   = trim($this->input->post('username', 'true'));
  21.         $password   = trim($this->input->post('password', 'true'));
  22.  
  23.         $temp_user  = $this->administrator_model->get_user($username)->row();
  24.         $num_user   = count($temp_user);
  25.  
  26.         $this->form_validation->set_rules('username', 'Username', 'trim|required');
  27.         $this->form_validation->set_rules('password', 'Password', 'trim|required');
  28.  
  29.         if ($this->form_validation->run() == FALSE) {
  30.             $this->load->view('administrator_view');
  31.         } else {
  32.             if ($num_user == 0) {
  33.                 $this->session->set_flashdata('notification','<b>Maaf !! Username Anda Tidak Terdaftar.</b>');
  34.                 redirect(site_url('administrator'));
  35.             } elseif ($num_user > 0) {
  36.                 $temp_account = $this->administrator_model->check_user_account($username, sha1($password))->row();
  37.                 $num_account = count($temp_account);
  38.  
  39.                 if ($num_account > 0) {
  40.                     $array_item = array('username'                  => $temp_account->user_username,
  41.                                         'nama'                      => $temp_account->user_name,
  42.                                         'avatar'                    => $temp_account->user_avatar,
  43.                                         'level'                     => $temp_account->user_level,
  44.                                         'logged_in_dagsar'          => TRUE
  45.                                         );
  46.                     $this->session->set_userdata($array_item);
  47.  
  48.                     redirect(site_url('admin/home'));
  49.                 } else {
  50.                     $this->session->set_flashdata('notification','<b>Login Gagal, Username atau Password Salah.</b>');
  51.                     redirect(site_url('administrator'));
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     public function logout() {
  58.         $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
  59.         $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
  60.         $this->output->set_header('Pragma: no-chace');
  61.         $this->session->sess_destroy();
  62.         redirect(base_url());
  63.     }
  64. }
  65. /* Location: ./application/controller/Administrator.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement