Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2.  
  3. class Auth extends CI_Controller {
  4.    
  5.     function __construct()
  6.     {
  7.         parent::__construct();
  8.     }
  9.    
  10.     function index()
  11.     {
  12.        
  13.     }
  14.    
  15.     function login()
  16.     {
  17.         $this->load->model('auth_model');
  18.        
  19.         $username = $this->input->post('username');
  20.         $password = $this->input->post('password');
  21.        
  22.         if ($this->auth_model->validate_login($username, $password))
  23.         {
  24.             // login success
  25.        
  26.             $this->session->set_userdata('logged_in', TRUE);
  27.            
  28.             if ($this->auth_model->validate_admin($username))
  29.             {
  30.                 $this->session->set_userdata('is_admin', TRUE);
  31.             }
  32.             else
  33.             {
  34.                 $this->session->set_userdata('is_admin', FALSE);
  35.             }
  36.            
  37.             $session_id = $this->session->userdata('session_id');
  38.             if ($this->session->userdata('logged_in'))
  39.             {
  40.                 echo 'Logged in!';
  41.                 echo "<br>";
  42.                 echo $session_id;
  43.             }
  44.         }
  45.         else
  46.         {
  47.             // login failed
  48.             echo 'Login failed';
  49.         }
  50.     }
  51.    
  52.     function logout()
  53.     {
  54.         $this->session->sess_destroy();
  55.        
  56.         redirect('home');
  57.     }
  58. }
  59.  
  60.  
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement