CodeIgniter Forums
Session destroing flashdata - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Session destroing flashdata (/showthread.php?tid=63526)



Session destroing flashdata - Underzzoo - 11-09-2015

Hi guys, i'm brazilian, and sorry about my english.

Ok, let's go to the problem:

I'm trying to make a logoff button, and when a user click in logoff, i call the function logoff:

function logoff(){
        $this->session->sess_destroy();
        $this->session->unset_userdata(array('user_id', 'user_nome', 'user_admin', 'user_logado'));
        set_msg('logoff', 'Logoff efetuado com sucesso.', 'sucesso');
        redirect('usuarios/login');
    }

but, when i destroy the session, i can't create a new one to display the message that was set in 'set_msg' function.

I've two function in my helper to display it:

function set_msg($id = 'msgerro', $msg = NULL, $tipo = 'erro'){
    $CI =& get_instance();
    switch($tipo):
        case 'erro':
            $CI->cookies->set_flashdata($id, '<div class="alert-box alert radius">'.$msg.'</div>');
        break;
        
        case 'sucesso':
            $CI->session->set_flashdata($id, '<div class="alert-box sucess radius">'.$msg.'</div>');
        break;
    
        default:
            $CI->session->set_flashdata($id, '<div class="alert-box radius">'.$msg.'</div>');
        break;
    
    endswitch;        
}

//Verifica se existe uma mensagem para exibir na tela atual.
function get_msg($id, $print = TRUE){
    $CI =& get_instance();
    $flash = $CI->session->flashdata($id);  THAT VALUE WAS COMING NULL BECAUSE OF SESSION DESTROY.
    var_dump($flash);
    if(isset($flash)){
        if($print){
            echo $flash;
            return TRUE;
        }
        else{
            return $CI->session->flashdata($id);
        }
    }



Make sense?
Someone have a hint to give me, how to fix this problem?

My CI version is 3.0.3
in old versions, people type $this->session->create(); and it's work very well..

Heelp me!


RE: Session destroing flashdata - ivantcholakov - 11-09-2015

Code:
$this->session->sess_destroy();

For this case I would replace it with:

Code:
$this->session->sess_regenerate(TRUE); // TRUE here destroys the session data.

http://www.codeigniter.com/user_guide/libraries/sessions.html#CI_Session::sess_regenerate


RE: Session destroing flashdata - skunkbad - 11-09-2015

If all you are doing is showing a message that the user successfully logged out, then why not just redirect to a place where the message is displayed. For instance /login?logout=1. By doing that, the user can choose to log back in again, and you can use the logout query parameter to show the logout confirmation.


RE: Session destroing flashdata - CroNiX - 11-12-2015

nevermind