php - Session in codeigniter not working well -
i can't figure out what's actual error session in codeigniter. other project working code. in case, got problem.
for login session code is:
$data = array( 'username' => $this->input->post('username'), 'admin_logged_in' => true, 'logged_in' =>true ); $this->session->set_userdata($data);
and check session as:
if ($this->session->userdata('admin_logged_in') == true) { // code }
before going controller checking session above , if session not true redirecting login page.
for logout:
function logout() { if ($this->session->userdata('admin_logged_in') == true) { $useremail = $this->session->userdata('username'); $data = array( 'username' => $useremail, 'admin_logged_in' => true, 'logged_in' =>true ); $this->session->unset_userdata($data); $this->session->sess_destroy(); redirect('login'); } }
but above code not working me. when logout, page redirected logout page session not destroyed since can access page needs session set. please me.
updated
i got strange problem. when log system , logout. , trying access method needs session. can access if wrote method name without index.php. , cannot access method needs session if wrote method name index.php. example: bnw needs session set in order go furthur. if login , logout then, if write in borwser url following:
example.com/index.php/bnw //it redirects login page. example.com/bnw //it logs in directly.
- does removing
index.php
.htaccess gives problem session?
put inside logout function,
works me
$user_data = $this->session->all_userdata(); foreach ($user_data $key => $value) { if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') { $this->session->unset_userdata($key); } } $this->session->sess_destroy();
Comments
Post a Comment