Advertisement
dewa_01

Untitled

Dec 15th, 2019
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login extends CI_Controller {
  4.  
  5.     public function index()
  6.     {
  7.         $this->form_validation->set_rules('username','Username','required|alpha_numeric');
  8.         $this->form_validation->set_rules('password','Password','required|alpha_numeric');
  9.        
  10.         if($this->form_validation->run() == FALSE)
  11.         {
  12.             $this->load->view('form_login');
  13.         } else {
  14.             $this->load->model('model_users');
  15.             $valid_user = $this->model_users->check_credential();
  16.            
  17.             if($valid_user == FALSE)
  18.             {
  19.                 $this->session->set_flashdata('error','Wrong Username / Password!');
  20.                 redirect('login');
  21.             } else {
  22.                 // if the username and password is a match
  23.                 $this->session->set_userdata('username', $valid_user->username);
  24.                 $this->session->set_userdata('group', $valid_user->group);
  25.                
  26.                 switch($valid_user->group){
  27.                     case 1 : //admin
  28.                                 redirect('admin/products');
  29.                                 break;
  30.                     case 2 : //member
  31.                                 redirect(base_url());
  32.                                 break;
  33.                     default: break;
  34.                 }
  35.             }
  36.         }
  37.     }
  38.     public function logout()
  39.     {
  40.         $this->session->sess_destroy();
  41.         redirect('login');
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement