Postingan lainnya
Cara menambahkan variable pada session
Bagiamana cara menambahkan variable array pada session? jadi disini session hanya berisi
array(2) { ["__ci_last_regenerate"]=> int(1569293976) ["tugas"]=> string(5) "users" }
nah saya mau menambahkan 'department' setelah "users" pada array diatas, baimana caranya?
public function login()
{
$ceks = $this->session->userdata('tugas');
if (isset($ceks)) {
redirect('');
} else {
$this->load->view('web/header');
$this->load->view('web/login');
$this->load->view('web/footer');
if (isset($_POST['btnlogin'])) {
$username = htmlentities(strip_tags($_POST['username']));
$pass = htmlentities(strip_tags(md5($_POST['password'])));
$dept = htmlentities(strip_tags($_POST['dept']));
$query = $this->Mcrud->get_data_by_pk('tbl_user', 'username', $username);
$cek = $query->result();
$cekun = $cek[0]->username;
$jumlah = $query->num_rows();
if ($jumlah == 0) {
$this->session->set_flashdata(
'msg',
'
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
<strong>Maaf "' . $username . '"</strong>tidak memiliki hak akses.
</div>'
);
redirect('web/login');
} else {
$row = $query->row();
$cekpass = $row->password;
if ($cekpass <> $pass) {
$this->session->set_flashdata(
'msg',
'<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
<strong>Username atau Password Salah!</strong>.
</div>'
);
redirect('web/login');
} else {
//
$row = $query->row();
$cekdept = $row->dept;
if ($cekdept <> $dept) {
$this->session->set_flashdata(
'msg',
'<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">× </span>
</button>
<strong>Department Salah!</strong>.
</div>'
);
redirect('web/login');
} else {
//
$this->session->set_userdata('tugas',"$cekun");
redirect('web');
}
}
}
}
}
}
1 Jawaban:
<a href='https://codeigniter.com/user_guide/libraries/sessions.html#adding-session-data'>referensi</a>
<pre> $this->session->set_userdata('some_name', 'some_value'); </pre>
Tanggapan
kita asumsikan 'some_value'='cekun', $cekun = array( 'username'=>$cek[0]->username, 'dept'=>$cek[0]->dept ); ketika aku pake itu, kenapa 'cekun' berubah jadi Severity: Notice Message: Trying to get property of non-object