Guest User

Untitled

a guest
Jun 9th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1.     public function login()
  2.     {
  3.         // Este también funciona perfect. :D
  4.         $d['titulo'] = 'Mangani.me - Loguearse';
  5.         $this->load->library('form_validation');
  6.         $this->form_validation->set_rules('username', 'Username', 'required');
  7.         $this->form_validation->set_rules('password', 'Password', 'required');
  8.         $d['contenido'] = '<form method="post" accept-charset="utf-8"><table border="0" cellspacing="0" cellpadding="5">'."\n";
  9.         $d['contenido'] .= '<tr><td><strong>Nickname:</strong></td>';
  10.         $data = array(
  11.             'name'        => 'username',
  12.             'id'          => 'username',
  13.             'value'       => '',
  14.             'size'        => '20',
  15.             );
  16.         $d['contenido'] .= '<td>'.form_input($data).'</td></tr>'."\n".'<tr><td><strong>Contraseña:</strong><td>';
  17.         $data2 = array(
  18.             'name'        => 'password',
  19.             'type'          => 'password',
  20.             'value'       => '',
  21.             'size'        => '20',
  22.             );
  23.         $d['contenido'] .= form_input($data2) . '</td></tr>'."\n".'<tr><td>'. form_submit('submit', '¡Loguearme!') .'</td></tr></table>'. form_close();
  24.         if ($this->form_validation->run() == FALSE)
  25.         {
  26.             $this->load->view('form', $d);
  27.         }
  28.         else
  29.         {
  30.             $query = $this->db->query("SELECT * FROM users WHERE username='".$this->input->post('username')."' AND password='".md5($this->input->post('password'))."' LIMIT 0,1");
  31.             $user = $query->row();
  32.             $this->db->query("DELETE FROM sessions WHERE ip='".$this->db->escape_str($this->user->ipaddress)."' AND sid != '".$this->user->sid."'");
  33.             $this->db->query("UPDATE sessions SET uid='".$user->uid."' WHERE sid='".$this->user->sid."'");
  34.             $this->input->set_cookie('mnuser', $user->uid."_".$user->loginkey, time()+3600, '.redmangani.me', '/', '', true);
  35.             $this->input->set_cookie('mnsid', $this->user->sid, time()+3600, '.redmangani.me', '/', '', true);
  36.             header('Location: index');
  37.         }
  38.     }
  39.     public function logout()
  40.     {
  41.         // Este funciona perfect. :D
  42.         global $user;
  43.         $this->input->set_cookie('mnuser', '', -3600, '.redmangani.me', '/', '', true);
  44.         $this->input->set_cookie('mnsid', '', -3600, '.redmangani.me', '/', '', true);
  45.         if($user->uid)
  46.         {
  47.             $time = time() - 900;
  48.             $this->db->delete('sessions', array('sid' => $this->user->sid));
  49.             $this->db->query("UPDATE users SET lastactive='".$time."' WHERE uid='".$user->uid."'");
  50.         }
  51.         header('Location: index');
  52.     }
Add Comment
Please, Sign In to add comment