Welcome Guest, Not a member yet? Register   Sign In
lost sessions in plain CI 2.1.4 install
#1

[eluser]mlieshout[/eluser]
Hi,

I know this has been asked many, many times on this forum, but I keep losing sessions in a CI 2.1.4 website. The sessions gets destroyed in Session.php, when the session data getting back from $this->_unserialize($session) is no longer in the correct format.

To make sure it's not caused by the code I wrote, I've ran the same tests in a plain CI 2.1.4 download with these settings:

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

$config['cookie_prefix'] = "";
$config['cookie_domain'] = ".ci2";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;

$config['global_xss_filtering'] = TRUE;

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

CREATE TABLE `ci_sessions` (
`session_id` varchar(40) NOT NULL DEFAULT '0',
`ip_address` varchar(45) NOT NULL DEFAULT '0',
`user_agent` varchar(120) NOT NULL,
`last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`),
KEY `last_activity_idx` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The test is done with jMeter and simulates a number of 100 Threads (users). All it does is a GET on the index.php. It gives lots of dropped sessions.

I've searched the forum, tried several solutions (like base64_encode/base64_decode in the _unserialize() and _serialize() functions) but it keeps loosing sessions. So, I'm kind of stuck. Anyone knows a working solution for this problem?
#2

[eluser]Doosje[/eluser]
Have you found a solution? I happens here too but not all the btw.
#3

[eluser]mlieshout[/eluser]
I've upgraded the web app to the CI 3.0-development trunk. There is no way you can fix this in CI 2.1.4
#4

[eluser]Doosje[/eluser]
huh, no way to fix it? Do you know where the problem is located?
Or is it the "not native" session handling?

thx for your quick answer btw;-)
#5

[eluser]mlieshout[/eluser]
I believe the problem is located in the Session library in CI 2.x. I've spent way to many hours on this problem, so upgrading to CI 3.0 was the best option for me. The sessions are far more stable than in CI 2.x.

Just give it a try Smile
#6

[eluser]Doosje[/eluser]
bedankt! ^_^
#7

[eluser]mlieshout[/eluser]
Graag gedaan Wink
#8

[eluser]Doosje[/eluser]
here's a solution for those who can't update atm.

https://degreesofzero.com/article/fixing...niter.html
#9

[eluser]InsiteFX[/eluser]
You don't autoload MY_Session you autoload the Session library it will find the MY_Session

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* ------------------------------------------------------------------------
* Created by Php Designer 8.
* Date : 5/6/2012
* Time : 11:19:06 PM
* ------------------------------------------------------------------------
*
* Class MY_Session
*
* @package  Package  CodeIgniter
* @subpackage Subpackage session
* @category category sessions
* @author  Raymond L King Sr.
* @link  http://example.com
* ------------------------------------------------------------------------
* To change this template use File | Settings | File Templates.
* ------------------------------------------------------------------------
*/

/**
* ------------------------------------------------------------------------
* 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 or xajax calls
     *
     * @access    public
     * @return    void
     */
    public function sess_update()
{
  $_ci =& get_instance();

  $ajax = $_ci->input->is_ajax_request();

  if ($ajax === FALSE)
  {
   parent::sess_update();
  }
    }

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

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

  parent::sess_destroy();
}

} // End of Class.

/**
* ------------------------------------------------------------------------
* Filename: MY_Session.php
* Location: ./application/libraries/MY_Session.php
* ------------------------------------------------------------------------
*/




Theme © iAndrew 2016 - Forum software by © MyBB