Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 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.             $userinfo = $this->auth_model->get_info($username);
  26.            
  27.             print_r($userinfo);
  28.            
  29.             $this->session->set_userdata('logged_in', TRUE);
  30.            
  31.             if ($this->auth_model->validate_admin($username))
  32.             {
  33.                 $this->session->set_userdata('is_admin', TRUE);
  34.             }
  35.             else
  36.             {
  37.                 $this->session->set_userdata('is_admin', FALSE);
  38.             }
  39.            
  40.             $session_id = $this->session->userdata('session_id');
  41.             if ($this->session->userdata('logged_in'))
  42.             {
  43.                 echo 'Logged in!';
  44.                 echo "<br>";
  45.                 echo $session_id;
  46.             }
  47.         }
  48.         else
  49.         {
  50.             // login failed
  51.             echo 'Login failed';
  52.         }
  53.     }
  54.    
  55.     function logout()
  56.     {
  57.         $this->session->sess_destroy();
  58.        
  59.         redirect('home');
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement