Advertisement
Guest User

a

a guest
Jul 7th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3. class Login extends CI_Controller{
  4. function __construct(){
  5. parent::__construct();
  6. $this->load->model('m_login'); // Memanggil Model Login
  7.  
  8. }
  9. function index(){
  10. $this->load->view('v_login'); // Memanggil View Login
  11. }
  12. function cek(){ // Berfungsi untuk mencheck user & pasword
  13. $this->load->library('form_validation');
  14. $this->form_validation->set_rules('username','username','trim|required|xss_clean');
  15. $this->form_validation->set_rules('password','password','trim|required|md5');
  16. $username = $this->input->post('username');
  17. $password = md5($this->input->post('password'));
  18. $data = array(
  19. 'username' => $username,
  20. 'password' => $password
  21. );
  22. if($this->form_validation->run() == true){
  23. $cek = $this->m_login->cek($data);
  24. $data = $this->m_login->data($data);
  25. if($cek > 0){
  26. $session = array(
  27. 'id' => $data[0]->id,
  28. 'nama' => $data[0]->username,
  29. 'status' => 'login'
  30. );
  31. $this->session->set_userdata($session);
  32. redirect('admin/index');
  33. }else{
  34. redirect('login/index/gagal');
  35. }
  36. }
  37. function logout(){
  38. $this->session->sess_destroy();
  39. redirect('welcome');
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement