Postingan lainnya
Cara menampilkan user yg sedang online
Perimisi gan, ane mau bertanya. bagaimana cara menampilkan siapa saja user yang sedang online.
user_table
id name username password alamat kontak
1 anton anton **** bogor 6281****
2 lala lala **** depok 6281****
Controllernya
public function login(){
$data = array(
'judul' => 'Masuk'
);
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if($this->form_validation->run() === FALSE){
$this->load->view('global/header');
$this->load->view('administrators/login', $data);
$this->load->view('global/footer');
}else{
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
$user_id = $this->administrator_model->login($username, $password);
if($user_id->num_rows() > 0){
$data = $user_id->row_array();
$kontak = $data['kontak'];
$alamat = $data['alamat'];
//session
$user_data = array(
'user_id' => $user_id,
'kontak' => $kontak,
'alamat' => $alamat,
'logged_in' => true
);
// print_r($user_data);
// die();
$this->session->set_userdata($user_data);
}else{
$this->session->set_flashdata('login_failed', 'Username atau password anda salah');
redirect('administrators/login');
}
}
}
Modelnya
public function login($username,$password){
$this->db->where('username',$username);
$this->db->where('password',$password);
$result = $this->db->get('administrators',1);
return $result;
}
Kira2 apa yang mesti ane tambah agar ane tahu siapa aja user yang sedang online. Terima kasih sebelumnya...
3 Jawaban:
kamu bisa cek kesini <a href=' https://stackoverflow.com/questions/52350853/how-to-display-the-live-online-user-in-the-system-using-codeigniter '>stackoverflow</a>
coba di user_table tambahin kolom online isi pilihan dengan 1 dan 0 misalnya
nah code tambah ini
<pre>
("SELECT name
FROM user_table
WHERE online
= '1'");
while ($ol = $db->fetchArray()) { ?>
<div class="media-body">
User Online
<strong><?php echo ucwords($ol['name']);?></strong>
</div>
</pre>
di logout.php tambah kode ini
<pre>
("UPDATE user_table SET online
= '0' WHERE username
= '$username'");
session_destroy();
</pre>