CodeIgniter Forums
session and cookie question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: session and cookie question (/thread-71112.html)



session and cookie question - lsepolis123 - 07-07-2018

PHP Code:
    public function logout() {

        
$this->session->unset_userdata('logged_in');
        
$this->session->unset_userdata('user_id');
        
$this->session->unset_userdata('username');
        
$this->session->sess_destroy();

        
// Message
        
$this->session->set_flashdata('success''You are logged out!');

        
redirect('admin/users/login');
    } 


IS the above code - deletes and cookies? If put this >>> // inside logout() getting 500 ERROR AFTER LOGOUT, WHAT TO DO TO DELETE COOKIES???

PHP Code:
if ($this->input->get_cookie('user_id') !== NULL) {
$this->input->delete_cookie('user_id');
$this->input->delete_cookie('username');
$this->input->delete_cookie('logged_in');



// SET IN LOGIN SECTION AS

PHP Code:
// SET IN LOGIN SECTION AS 

if ($remember == 1) {
$cookie = array( 
'name'   => 'user_id'
'value'  => $user_id
'domain' => ''
'path'   => '/'
'prefix' => ''
'secure' => FALSE 
); 

// Set the cookie to confirmed 
$this->input->set_cookie($cookie); 

$cookie = array( 
'name'   => 'username'
'value'  => $username
'domain' => ''
'path'   => '/'
'prefix' => ''
'secure' => FALSE 
); 

// Set the cookie to confirmed 
$this->input->set_cookie($cookie); 

$cookie = array( 
'name'   => 'logged_in'
'value'  => 'true'
'domain' => ''
'path'   => '/'
'prefix' => ''
'secure' => FALSE 
); 

// Set the cookie to confirmed 
$this->input->set_cookie($cookie); 



RE: session and cookie question - Pertti - 07-08-2018

Try to switch on logging and see if a specific error is logged.

Tho in your code, the one thing I would check is session destroy method. You are destroying the session, then adding flash-data to session, there might be some conflict with that - you might have to recreate session before you can call set_flashdata.