Advertisement
arisafrianto

c_login.php

Sep 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') or exit ('Akses langsung tidak diperbolehkan');
  3.  
  4. /**
  5.  *
  6.  */
  7. class c_login extends CI_Controller{
  8.  
  9.   public function __construct(){
  10.     parent::__construct();
  11.     if ($this->session->userdata('username')) {
  12.       redirect(base_url('admin'));
  13.     }
  14.     $this->load->model(array('m_login'));
  15.   }
  16.  
  17.   public function index(){
  18.     $this->load->view('login');
  19.   }
  20.  
  21.   public function proses(){
  22.     $this->form_validation->set_rules('username','username','required|trim|xss_clean');
  23.     $this->form_validation->set_rules('password','password','required|trim|xss_clean');
  24.     if ($this->form_validation->run() == FALSE){
  25.       $this->load->view('login');
  26.     }
  27.     else {
  28.       $user = $this->input->post('username');
  29.       $pass = $this->input->post('password');
  30.       $u    = $user;
  31.       $p    = sha1($pass);
  32.       $cek  = $this->m_login->cek($u,$p);
  33.       if ($cek->num_rows() > 0){
  34.         foreach ($cek->result() as $row){
  35.           $sess_data['username'] = $row->username;
  36.           $sess_data['password'] = $row->passsword;
  37.           $sess_data['nama']     = $row->nama;
  38.           $this->session->set_userdata($sess_data);
  39.         }
  40.         $this->session->set_flashdata('succes','login berhasil');
  41.         redirect('c_admin/admin');
  42.       }
  43.       else{
  44.         $this->session->set_flashdata('result_login', 'Username atau Password yang anda masukkan salah.');
  45.         redirect('c_login/login');
  46.       }
  47.     }
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement