Welcome Guest, Not a member yet? Register   Sign In
problem with Sess_destroy()
#1

[eluser]Marcone Ramos[/eluser]
I'm new to codeigniter and still learning basic things.
Right now I am having a hard time trying to destroy my sessions. The problem is that the sessions never get destroyed. The script seems to ignore the sess_destroy() and doesn't return any error.

autoload.php
Code:
/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
|    $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array('database','session', 'form_validation');

the controller

Code:
class C_loginsyslogin extends CI_Controller{

  
    function index()
    {
        // LOAD LIBRARIEs
        $this->load->library(array('encrypt', 'form_validation'));
        // LOAD HELPERS
        $this->load->helper(array('form', 'url'));
        $loadTemp['varScript']='';
        $loadTemp['varContent']='v_loginsyslogin';
        $this->load->view('v_admintemplate', $loadTemp);
        
    }    

//logout
    function logout()
    {
        $this->session->sess_destroy();
        $isLogged=$this->session->userdata("userId");
        if ($isLogged=="") {
            redirect('c_loginsyslogin','refresh');
        } else {
            echo 'Problemas na hora de realizar o logout';
            echo $isLogged;
            $this->session->userdata("userId");
        }
    }

//reportlogin
    function reportlogin(){
        /*
        THIS CONTROLER IS JUST TO LOG THE CLIENT TO THE REPORT
        */
        
        $this->load->helper(array('form', 'url'));
        $this->load->model('Loginmodel');
        if ($this->Loginmodel->checkUserByEmail($this->input->post('txtusername'), $this->input->post('txtpassword'))) {
            //get the user id by the email
            $tempid=$this->Loginmodel->getIdByEmail($this->input->post('txtusername'));
            //gets the user type user a (administrator), c (simple user, visitor or client) and check if he's allowed to see this page
            $temputype=$this->Loginmodel->getUserTypeById($tempid);
            
            //gets the user login name
            $temploginname=$this->Loginmodel->getLoginNameById($tempid);
            //gets the user email from the database.
            
            //create a session
            
            $this->session->set_userdata('userName', $temploginname);
            $this->session->set_userdata('email', $this->input->post('txtusername'));
            $this->session->set_userdata('uType', $temputype);
            $this->session->set_userdata('userId', $tempid);
            
             /*v170511
            
             $_SESSION['userName']=$temploginname;
             $_SESSION['email']=$this->input->post('txtusername');
             $_SESSION['uType']=$temputype;
             $_SESSION['userId']=$tempid;*/
            
            if ($temputype != 'none') {
                if ($temputype=="a") {
                    //if "a" administrator or memeber.
                    
                    redirect('/c_loginsyslogin/reportpost', 'refresh');
                } else if ($temputype=="m"){
                    redirect('/c_loginsyslogin/showReportBlog', 'refresh');
                }
            } else {
            //for debug
            echo 'Not found';
            exit;
            }
            
        //for debug
            
        exit;
        } else {
        //for debug
            echo 'favor logar '. $this->input->post('txtusername');
        exit;
            
        }
    }
}

thanks
#2

[eluser]toopay[/eluser]
What you mean session never destroyed? In what function on your controller you found that session never destroyed? Also, you may use unset_userdata instead sess_destroy.
#3

[eluser]InsiteFX[/eluser]
It destories the session but it is still left in the database until the garbage collection cleans it up which you do not know when!

Try this:
Code:
//logout
    function logout()
    {
        $this->userdata = array();
        $this->session->sess_destroy();
        $isLogged=$this->session->userdata("userId");
        if ($isLogged=="") {
            redirect('c_loginsyslogin','refresh');
        } else {
            echo 'Problemas na hora de realizar o logout';
            echo $isLogged;
            $this->session->userdata("userId");
        }
    }

InsiteFX
#4

[eluser]Marcone Ramos[/eluser]
thank you guys! It works now.




Theme © iAndrew 2016 - Forum software by © MyBB