Guest User

Untitled

a guest
Apr 3rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL ^ E_NOTICE);
  3.  
  4. class Login extends CI_Controller {
  5. public function _construct()
  6. {
  7. parent::_construct();
  8. $this->load->model('MUser');
  9. }
  10.  
  11. public function index()
  12. {
  13. if ($this->session->userdata('logged') == true ) {
  14. redirect('rental') ;
  15. }else{
  16. $this->load->view('login');
  17. }
  18. }
  19.  
  20. public function validasi()
  21. {
  22. $this->load->library('Form_validation');
  23. $this->form_validation->set_rules('username', 'Username', 'required');
  24. $this->form_validation->set_rules('password', 'Password', 'required');
  25.  
  26. if($this->form_validation->run() == true) {
  27. $username = $this->input->post('username');
  28. $password = $this->input->post('password');
  29.  
  30. if($this->MUser->CheckUser ($username,$password) == true) {
  31. $data = array('username'=>$username, 'logged'=> true);
  32. $this->session->set_userdata($data);
  33. redirect('rental');
  34.  
  35. }else{
  36. $this->session->set_flashdata('pesan', 'Username atau password anda salah');
  37.  
  38. redirect('Login');
  39. }
  40.  
  41. } else {
  42. $this->load->view('login');
  43. }
  44. }
  45.  
  46. public function logout()
  47. {
  48. $this->session->session_destroy();
  49. redirect('Login', 'referesh');
  50. }
  51. }
  52. ?>
  53.  
  54. <?php
  55. error_reporting(E_ALL ^ E_NOTICE);
  56.  
  57. class MUser extends CI_Model {
  58. public $table = "user";
  59. public function _construct()
  60. {
  61. parent::_construct();
  62. }
  63. public function CheckUser($username, $password) {
  64. $query = $this->db->get_where($this->table, array('username'=>$username, 'password'=>$password));
  65. if($query->num_rows() > 0)
  66. {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. }
  73. ?>
Add Comment
Please, Sign In to add comment