Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Login extends CI_Controller {
  5.  
  6.     public function __construct(){
  7.         parent::__construct();
  8.         $this->load->model('m_login');
  9.     }
  10.  
  11.     public function index()
  12.     {
  13.         $this->load->view('v_login');
  14.     }
  15.  
  16.     public function aksi_login(){
  17.         $username = $this->input->post('username');
  18.         $password = $this->input->post('password');
  19.         $where = array(
  20.             'username' => $username,
  21.             'password' => md5($password)
  22.             );
  23.         $cek = $this->m_login->cek_login("admin", $where)->num_rows();
  24.         if($cek > 0){
  25.             $data_session = array(
  26.                 'nama' => $username,
  27.                 'status' => 'login'
  28.                 );
  29.             $this->session->set_userdata($data_session);
  30.             redirect(base_url('admin'));
  31.         }else{
  32.             echo "<script>alert('username atau password salah')</script>";
  33.             $this->index();
  34.         }
  35.     }
  36.  
  37.     public function logout(){
  38.         $this->session->sess_destroy();
  39.         redirect(base_url('login'));
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement