Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL ^ E_NOTICE);
- class Login extends CI_Controller {
- public function _construct()
- {
- parent::_construct();
- $this->load->model('MUser');
- }
- public function index()
- {
- if ($this->session->userdata('logged') == true ) {
- redirect('rental') ;
- }else{
- $this->load->view('login');
- }
- }
- public function validasi()
- {
- $this->load->library('Form_validation');
- $this->form_validation->set_rules('username', 'Username', 'required');
- $this->form_validation->set_rules('password', 'Password', 'required');
- if($this->form_validation->run() == true) {
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- if($this->MUser->CheckUser ($username,$password) == true) {
- $data = array('username'=>$username, 'logged'=> true);
- $this->session->set_userdata($data);
- redirect('rental');
- }else{
- $this->session->set_flashdata('pesan', 'Username atau password anda salah');
- redirect('Login');
- }
- } else {
- $this->load->view('login');
- }
- }
- public function logout()
- {
- $this->session->session_destroy();
- redirect('Login', 'referesh');
- }
- }
- ?>
- <?php
- error_reporting(E_ALL ^ E_NOTICE);
- class MUser extends CI_Model {
- public $table = "user";
- public function _construct()
- {
- parent::_construct();
- }
- public function CheckUser($username, $password) {
- $query = $this->db->get_where($this->table, array('username'=>$username, 'password'=>$password));
- if($query->num_rows() > 0)
- {
- return true;
- } else {
- return false;
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment