Guest User

Untitled

a guest
Jun 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3.  
  4. /**
  5.  * Description of login_form
  6.  *
  7.  * @author apocalipse89
  8.  */
  9. class Login extends CI_Controller
  10. {
  11.     public function __construct()
  12.     {
  13.         parent::__construct();
  14.         //$this->load->model('User','user'); /* This call the model to retrieve data from db */
  15.     }
  16.    
  17.     public function index()
  18.     {
  19.         if(!file_exists('application/views/login.php'))
  20.         {
  21.             show_404();
  22.         }
  23.        
  24.         $this->load->library('form_validation');
  25.         $this->load->helper('form');
  26.         $this->load->helper('html');
  27.         $this->load->library('session');
  28.         $this->load->helper('url');
  29.        
  30.         $this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>');
  31.        
  32.         $this->form_validation->set_rules('username','username','trim|required|xss_clean');
  33.         $this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check');
  34.        
  35.         if($this->form_validation->run() == FALSE)
  36.         {
  37.             /* Data to pass to view */
  38.             $data['title'] = "User Access";
  39.             $data['author'] = "Salvatore Mazzarino";
  40.             $data['year'] = '34343434';
  41.            
  42.            
  43.             $this->load->view('login',$data);
  44.            /* $this->load->view('templates/_footer',$data);*/
  45.         }
  46.         else
  47.         {  
  48.            redirect('home');
  49.            
  50.         }
  51.     }
  52.      
  53.     public function pass_check($pass)
  54.     {        
  55.         $result = array('id'=>123,'username'=>'test1');
  56.                
  57.         if(!empty($result))
  58.         {            
  59.                 $session_array = array('id'=> $result['id'], 'username'=> $result['username']); /* Create a session passing user data */
  60.                
  61.                 $this->session->set_userdata('logged_in', $session_array);
  62.    
  63.                 return TRUE;
  64.         }
  65.         else
  66.         {
  67.             $this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!");
  68.             return FALSE;
  69.         }
  70.     }
  71. }
  72.  
  73. /* END OF FILE */
Add Comment
Please, Sign In to add comment