Advertisement
igun18

view and control

Jan 30th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <?php echo validation_errors(); ?>
  2. <form action="<?= base_url() ?>verifylogin" method="post" name="menuForm" class="form-horizontal">
  3. <div class="form-group">
  4. <div class="col-md-12">
  5. <label for="username"></label>
  6. <input type="text" class="form-control" placeholder="E-mail" id="txtusername"/>
  7. </div>
  8. </div>
  9.  
  10. <div class="form-group">
  11. <div class="col-md-12">
  12. <label for="password"></label>
  13. <input type="password" class="form-control" placeholder="Password" id="txtpassword"/>
  14. </div>
  15. </div>
  16. <br>
  17. <div class="form-group">
  18. <div class="col-md-6">
  19. <a href="#" class="btn btn-link btn-block">Forgot your password?</a>
  20. </div>
  21. <div class="col-md-6">
  22. <button class="btn btn-info btn-block">Log In</button>
  23. </div>
  24. </div>
  25. </form>
  26.  
  27. ------------------------------------
  28.  
  29. controller
  30. ---------------------
  31.  
  32.  
  33. <?php
  34. defined('BASEPATH') OR exit('No direct script access allowed');
  35.  
  36. class Verifylogin extends CI_Controller {
  37.  
  38. function __construct()
  39. {
  40. parent::__construct();
  41.  
  42.  
  43. $this->load->model('modLogin','',TRUE);
  44. }
  45.  
  46.  
  47. function index()
  48. {
  49. print_r( $this->input->post());
  50. $email = $this->input->post('txtusername');
  51. $password = $this->input->post('txtpassword',TRUE);
  52. // echo ' - ' . $password . $email;
  53.  
  54. die();
  55. $this->load->library('form_validation');
  56. $this->load->helper(array('form', 'url'));
  57. $this->form_validation->set_rules('username', 'Username', 'required');
  58. $this->form_validation->set_rules('password', 'Password', 'required');
  59. // $this->form_validation->set_rules('username', 'Username', 'trim|required|valid_email|xss_clean');
  60. //$this->form_validation->set_rules('password', 'Password', 'trim|required|sha1');
  61. $email = $this->input->post('username');
  62. $password = $this->input->post('password');
  63. echo $password . $email;
  64.  
  65. die();
  66.  
  67. if($this->form_validation->run() == FALSE)
  68. {
  69. $this->load->view('vlogin');
  70. }
  71. else
  72. {
  73. redirect('home', 'refresh');
  74. }
  75.  
  76. }
  77.  
  78. function check_database($password)
  79. {
  80. //Field validation succeeded. Validate against database
  81. $username = $this->input->post('username');
  82.  
  83. //query the database
  84. $result = $this->MLogin->login($username, $password);
  85.  
  86. if($result)
  87. {
  88. $sess_array = array();
  89. foreach($result as $row)
  90. {
  91. $sess_array = array(
  92. 'id' => $row->id,
  93. 'username' => $row->username
  94. );
  95. $this->session->set_userdata('logged_in', $sess_array);
  96. }
  97. return TRUE;
  98. }
  99. else
  100. {
  101. $this->form_validation->set_message('check_database', 'Invalid username or password');
  102. return false;
  103. }
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement