Advertisement
Guest User

Untitled

a guest
Apr 8th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. </head>
  2.  
  3. <body>
  4. <div class="container">
  5. <h3>Login</h3>
  6. <hr>
  7. <form action="<?php echo base_url('login/do_login')?>" method="POST">
  8. <div class="form-group">
  9. <label for="cari">USERNAME</label>
  10. <input type="text" name="usuario" id="usuario" class="form-control">
  11.  
  12. </div>
  13.  
  14. <div class="form-group">
  15. <label for="cari">PASSWORD</label>
  16. <input type="password" name="contrasena" id="contrasena" class="form-control">
  17.  
  18. </div>
  19.  
  20. <input class="btn btn-primary" type="submit" value="Login" name="login">
  21. <input class="btn btn-primary" type="reset" value="Reset">
  22.  
  23. </form>
  24. </div>
  25.  
  26.  
  27.  
  28. </body>
  29. </html>
  30.  
  31. <?php
  32.  
  33. Class Login extends CI_Controller{
  34.  
  35.  
  36. public function index(){
  37.  
  38.  
  39. $this->load->view('login_form');
  40.  
  41.  
  42. }
  43.  
  44. public function do_login()
  45. {
  46. // load the form_validation library
  47. $this->load->library('form_validation');
  48.  
  49. $this->form_validation->set_rules('usuario', 'Username', 'trim|required|min_length[3]|alpha_numeric');
  50. $this->form_validation->set_rules('contrasena', 'Password', 'trim|required|min_length[6]');
  51.  
  52. // if there is errors
  53. if ($this->form_validation->run() == FALSE) {
  54. // this will load your form with the errors
  55.  
  56. $this->load->view('login_form');
  57.  
  58. } else {
  59. // if no errors we will hit the database
  60. $user=$this->input->post('usuario', true);
  61. $pass=$this->input->post('contrasena', true);
  62. $cek = $this->m_login->proceso_login($user,$pass);
  63. $hasil=count($cek);
  64.  
  65. if($hasil > 0){
  66.  
  67. $pelogin =$this->db->get_where('usuarios',array('username' => $user, 'password' => $pass))->row();
  68.  
  69. if($pelogin ->type == 0){
  70. redirect('login/admin');
  71. }
  72.  
  73. else{
  74. redirect('login/usuario');
  75. }
  76. }
  77. redirect('login/index');
  78. }
  79. }
  80.  
  81.  
  82. public function home(){
  83.  
  84. $data['records']=$this->m_login->getDetails();
  85. $this->load->view('usuario',$data);
  86. }
  87.  
  88. public function getDetails()
  89. {
  90. $st=$this->db->SELECT('cursadas.*, usuarios.name as usuarios, materias.name as materias_name')->from('cursadas')
  91. ->join('usuarios','usuarios.id=cursadas.user_id')
  92. ->join('materias','materias.id=cursadas.subject_id')
  93. ->WHERE('cursadas.user_id=',$this->session->userdata['id'])
  94. ->get()->result_array();
  95. return $st[0]; // or use the row function
  96. }
  97.  
  98. <table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
  99. <thead>
  100. <th>id</th>
  101. <th>User</th>
  102. <th>Subject</th>
  103. <th>Grade</th>
  104. <th>Date</th>
  105. </thead>
  106.  
  107.  
  108. <tbody>
  109. <?php
  110.  
  111. if (count($records) > 0) {
  112. foreach($records as $record) {
  113.  
  114. echo "<tr>
  115. <td>".$record['id']."</td>
  116. <td>".$record['User']."</td>
  117. <td>".$record['name']."</td>
  118. <td>".$record['grade']."</td>
  119. <td>".$record['date']."</td>
  120. </tr>";
  121. }
  122.  
  123. }
  124. ?>
  125.  
  126. </tbody>
  127.  
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement