Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. public function do_login() {
  2. if ($this->session->userdata('is_admin_login')) {
  3. redirect('admin/home/dashboard');
  4. } else {
  5. $user = $_POST['username'];
  6. $password = $_POST['password'];
  7.  
  8. $this->form_validation->set_rules('username', 'Username', 'required');
  9. $this->form_validation->set_rules('password', 'Password', 'required');
  10.  
  11. if ($this->form_validation->run() == FALSE) {
  12. $this->load->view('admin/vwLogin');
  13. } else {
  14. $salt = '5&JDDlwz%Rwh!t2Yg-Igae@QxPzFTSId';
  15. $enc_pass = md5($salt.$password);
  16. $sql = "SELECT * FROM tbl_admin_users WHERE username = ? AND password = ?";
  17. $val = $this->db->query($sql,array($user ,$enc_pass ));
  18.  
  19. if ($val->num_rows) {
  20. foreach ($val->result_array() as $recs => $res) {
  21. $sess_array = array(
  22. 'id' => $res['id'],
  23. 'username' => $res['username'],
  24. 'email' => $res['email'],
  25. 'is_admin_login' => true,
  26. 'user_type' => $res['user_type']
  27. );
  28. $this->session->set_userdata($sess_array);
  29. }
  30. redirect('admin/dashboard');
  31. } else {
  32. $err['error'] = '<strong>Access Denied</strong> Invalid Username/Password';
  33. $this->load->view('admin/vwLogin', $err);
  34. }
  35. }
  36. }
  37. }
  38.  
  39. if (!defined('BASEPATH'))
  40. exit('No direct script access allowed');
  41.  
  42. class Dashboard extends CI_Controller {
  43.  
  44. public function __construct() {
  45. parent::__construct();
  46. $this->load->library('form_validation');
  47. dump_exit($this->session->userdata);
  48. if (!$this->session->userdata('is_admin_login')) {
  49. redirect('admin/home');
  50. }
  51. }
  52.  
  53. public function index() {
  54. $arr['page']='dash';
  55. $this->load->view('admin/vwDashboard',$arr);
  56. }
  57.  
  58. }
  59.  
  60. $autoload['libraries'] = array('database', 'session', 'form_validation');
  61. $autoload['helper'] = array('url', 'form', 'dump');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement