Guest User

Login.php

a guest
May 18th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 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.     /**
  7.      * Index Page for this controller.
  8.      *
  9.      * Maps to the following URL
  10.      *      http://example.com/index.php/welcome
  11.      *  - or -
  12.      *      http://example.com/index.php/welcome/index
  13.      *  - or -
  14.      * Since this controller is set as the default controller in
  15.      * config/routes.php, it's displayed at http://example.com/
  16.      *
  17.      * So any other public methods not prefixed with an underscore will
  18.      * map to /index.php/welcome/<method_name>
  19.      * @see https://codeigniter.com/user_guide/general/urls.html
  20.      */
  21.  
  22.     /*public function __construct()
  23.     {
  24.         parent::__construct();
  25.     }*/
  26.  
  27.     public function index()
  28.     {
  29.        
  30.         $this->load->view('login/index');
  31.     }
  32.  
  33.     public function masuk()
  34.     {
  35.         $username = $this->input->post('username');
  36.         $password = $this->input->post('password');
  37.  
  38.         $cek = $this->m_login->cek($username,$password);
  39.         if($cek->num_rows()==1)
  40.         {
  41.             foreach ($cek->result() as $data) {
  42.                 # code...
  43.                 $sess_data['id_username'] = $data->id_username;
  44.                 $sess_data['username'] = $data->username;
  45.                 $this->session->set_userdata($sess_data);
  46.             }
  47.             redirect('home');
  48.         }
  49.         else
  50.         {
  51.             $this->session->set_flashdata('pesan','Maaf username dan password tidak cocok!');
  52.             redirect('login');
  53.         }
  54.     }
  55.  
  56.     function keluar()
  57.     {
  58.         $this->session->sess_destroy();
  59.         redirect('login');
  60.     }
  61.  
  62. }
Add Comment
Please, Sign In to add comment