Advertisement
cahyadyazin

file login.php

Oct 23rd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php if(!defined('BASEPATH')) exit('Hacking Attempt : Keluar dari sistem..!!');
  2.     class Login extends CI_Controller {
  3.        
  4.         public function __construct() {
  5.             parent::__construct();
  6.    
  7.             $this->load->model('m_login');
  8.             $this->load->library(array('form_validation','session'));
  9.             $this->load->helper('url');
  10.    
  11.         }
  12.  
  13.         public function index() {
  14.             $session = $this->session->userdata('isLogin');
  15.    
  16.             if($session == FALSE) {
  17.                 redirect('login/login_form');
  18.             } else {
  19.                 redirect('home');
  20.             }
  21.         }
  22.  
  23.         public function login_form() {
  24.             $this->form_validation->set_rules('username', 'username', 'required|trim|xss_clean');
  25.             $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
  26.             $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
  27.    
  28.             if($this->form_validation->run()==FALSE) {
  29.                 $this->load->view('form_login');
  30.             } else {
  31.                 $username = $this->input->post('username');
  32.                 $password = $this->input->post('password');
  33.        
  34.                 $cek = $this->m_login->ambilPengguna($username, $password, 1);
  35.        
  36.                 if($cek->num_rows() <> 0) {
  37.                     $this->session->set_userdata('isLogin', TRUE);
  38.                     $this->session->set_userdata('data_user',$cek->row());
  39.          
  40.                     redirect('home');
  41.                 } else {
  42.                     echo " <script>
  43.                         alert('Gagal Login: Kombinasi Username Salah Atau Akun Belum Di Verifikasi!');
  44.                         history.go(-1);
  45.                         </script>";        
  46.                 }
  47.             }  
  48.         }
  49.  
  50.         public function logout() {
  51.             $this->session->sess_destroy();
  52.            
  53.             redirect('login/login_form');
  54.         }
  55.     }
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement