• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session lost on ci 1.7.2

#1
[eluser]siubie[/eluser]
Hi i have some trouble with codeigniter session, sometimes when i push "back" button or redirect after form submission i always lost the session.

my redirect code :

Code:
redirect('informasi/pegawai/detail_pegawai/'.$id_pegawai.'#tabs-2','refresh');

iam using jquery ui tabs that i need "#tabs-2" in the url to activate tabs number two, i also use 6 to 8 ajax call to load data in the page that redirected

my config

Code:
$config['sess_cookie_name']        = 'cisession';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']        = "/";

#2
[eluser]WanWizard[/eluser]
CI's session library is notorious for losing sessions when using a lot of ajax calls.

Try increasing the sess_time_to_update to a higher number.

#3
[eluser]siubie[/eluser]
hi wandwizard Smile
i search the forum a bit and found your post here :

http://ellislab.com/forums/viewthread/94915/P15/

i use that method u posted so far is good but is there any security risk with that code or maybe you have a newer piece of code ? Smile

#4
[eluser]WanWizard[/eluser]
It is safe, it just makes sure no session id rotation happens on ajax calls.

It might not solve all your problems though, depending on timing. But it will certainly improve things.

#5
[eluser]InsiteFX[/eluser]
One way to work around it!
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* ------------------------------------------------------------------------
* CI Session Class Extension for AJAX calls.
* ------------------------------------------------------------------------
*
* Save as application/libraries/MY_Session.php
*/

class MY_Session extends CI_Session {

    // --------------------------------------------------------------------

    /**
     * sess_update()
     *
     * Do not update an existing session on ajax calls
     *
     * @access    public
     * @return    void
     */
    public function sess_update()
    {
        if (is_ajax_request())
        {
            // set a higher timeout for Ajax calls.
            $this->sess_time_to_update = 1200;    // raise if you need more time!
            parenet::sess_update();
        }
    }

    // --------------------------------------------------------------------

    /**
     * sess_destroy()
     *
     * Clear's out the user_data array on sees::destory.
     *
     * @access    public
     * @return    void
     */
    public function sess_destroy()
    {
        $this->userdata = array();
        parent::sess_destroy();
    }

}

// ------------------------------------------------------------------------
/* End of file MY_Session.php */
/* Location: ./application/libraries/MY_Session.php */

InsiteFX

#6
[eluser]John V4lkyr[/eluser]
hi all, im a newbie in CI

i have the same problem with codeigniter session. i use session for my litle online store http://www.boss-sepatu.com
the session keep dissappear every time i navigate to another page after "add to cart" process whom store the data into the session.

I search the web and found a usefull CI plugin called native_session http://codeigniter.com/wiki/Native_session/. i just download and extract the file to my application/libraries of my codeigniter installation folder and then the problem is dissappear. i hope this will solve your problem too.

sorry my english is bad.

#7
[eluser]WanWizard[/eluser]
Do NOT use native sessions, unless you have taken special security measures server-side. PHP's session management by default is NOT secure.

Instead of trying to look for workarounds, debug your problem and fix it. There is nothing wrong with CI's session class, 99.999% of the time it's about the fact that your configuration is incorrect.

#8
[eluser]John V4lkyr[/eluser]
ok thanks WanWizard for your info..
but i dont know where to start fixing my problem when i using the built in CI session class..
btw i use codeigniter 1.72

#9
[eluser]siubie[/eluser]
im still on ci session not change to native session yet but so far code from wandwizard is going fine Smile

here is my config for session

Code:
$config['sess_cookie_name']        = 'cisession';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']        = "/";

#10
[eluser]WanWizard[/eluser]
@John V4lkyr,

If you're debugging, use firefox, and install the web developer toolbar and firebug. It allows you to check if the server does set the session cookie, and if it does, what the expiry of the cookie is. You can also check if the cookie is stored locally or not, and if it is sent back to the server with the next page request.

Solving the problem starts with debugging the problem. Once you have determined the cause of the problem, only then can you start working on the solution. Random changes (either config or alternative code / workarounds) in the hope it's going to work is the wrong approach.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.