CodeIgniter Forums
Session don't close - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Session don't close (/showthread.php?tid=43890)

Session don't close - El Forum - 07-27-2011

Hi all,

i have a little frustrating problem since two days... I had a disconnect button to my website and it don't works.

All is in the same controller : myaccount.

For each load, some global view are called. Account-box is a view with the "hello" and somes account infos...
class Myaccount extends CI_Controller {
    private $datas = array();
    public function __construct() {
        $datas = array();
        /*** session ***/
        $datas['account'] = $this->active_session->get_account($this->session->userdata('id'));
        /*** end session ***/
        /*** start global views ***/

        $this->datas['top_view'] = $this->load->view('global/top', $datas, true);
        $this->datas['top_menu_view'] = $this->load->view('global/top-menu', $datas, true);
        $this->datas['account_box_view'] = $this->load->view('global/account-box', $datas, true);
        $this->datas['footer_view'] = $this->load->view('global/footer', $datas, true);
        /*** end global views ***/

Here's the librarie Active_session called in the previous code :
public function get_account($user_id = false) {
        $CI =& get_instance();
        if ($user_id == false)
            return false;

        $return = $CI->account_model->get_by_id($user_id);
        if ($return == false)
            return false;
        $return['notification_count'] = $this->get_notification_count($user_id);
        $return['notifications'] = $this->get_notifications($user_id);
        return $return;


The open session code (redirect to the homepage if ok) :

public function identify() {

        $this->form_validation->set_error_delimiters('<div class="form-error">', '</div>');
        $this->form_validation->set_rules('account-email', 'Adresse e-mail', 'trim|required|valid_email|callback_mail_exists|xss_clean');
        $this->form_validation->set_rules('account-password', 'Mot de passe', 'trim|required|min_length[6]|max_length[20]|alpha_num|callback_password_exists|xss_clean');
        if ($this->input->post('check-form') == 'true') {
            if ($this->form_validation->run() == true) {
                try {
                    $account = $this->account_model->get_by_email($this->input->post('account-email'));
                    $this->session->set_userdata('id', $account['id']);
                    $this->session->set_userdata('rank', $account['rank']);
                    redirect('', 'refresh');
                } catch (Exception $e) {
        $this->load->view('myaccount/identify', $this->datas);

The close session code :
public function disconnect() {
        redirect('', 'refresh');

And, another thing perhaps usefull... I write my code in english but the url's must be in french. So, i have some routes :
$route['mon-compte/identifier'] = 'myaccount/identify';
$route['mon-compte/deconnecter'] = 'myaccount/disconnect';

The disconnect function don't seems to work... Thanks for your help and sorry for my english.

Session don't close - El Forum - 07-28-2011

Little up. Nobody have an idea ?

Session don't close - El Forum - 07-29-2011

I do some other test and here's the results : i try to unset the userdata vars and nothing happen so i try to change the values of the userdata created before and no changes.

Here's the config :

$config['sess_cookie_name']        = 'csj_session';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']    = FALSE;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'session';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300;

I don't understand why the CI session can read the values but can't change and destroy them. I read in the forum that the sess_destroy function doesn't work but never read that we can't modifiy the datas.

Thanks for your help.

Session don't close - El Forum - 07-29-2011

[eluser]Vlad Balmos[/eluser]
It's a wild guess but here it goes. CI Sessions are stored in plain cookies, and not the regular server side php sessions. If your site is hosted at, but you can access the site with or without the [www.], like: and, you will actually set 2 session cookies. One cookie for and the other one for
If you're browsing then switch to and then disconnect from you will delete only the session for, the other one still exists. So maybe there's a conflict there.

Check the cookies using Firebug and Firecookie for Firefox.

Hope it helps and i didn't give you a headache Smile

Session don't close - El Forum - 07-29-2011


thanks for your help. I Check this issue but it's not the problem.

I find what's wrong but it's still a problem... I used routes to redirect to the good controller and it seems that the redirect works perfectly but all the code before the redirect is not used. I don't know if it's a CI priority problem or another thing.

So, if i use CI like that, no problem :

Controller myaccount -> function disconnect { session close }

Navigator : = OK, disconnected

But not working :

Controller myaccount -> function disconnect { session close }

Config Route -> $routes['moncompte/deconnexion'] = 'myaccount/disconnect';

Navigator : = OK for redirect and view, not disconnected

Session don't close - El Forum - 07-29-2011

[eluser]Vlad Balmos[/eluser]
can't figure it out. The routing feature shouldn't interfere with session management... Maybe someone else here has some better ideeas. Good luck!

Session don't close - El Forum - 07-29-2011

I don't understand too...

I make a lot of tests and, separatly, everything works fine. Route + Session + Redirect seems to be the problem... Don't know why...