[eluser]skunkbad[/eluser]
I may have come up with a solution, but since I've never had problems with sessions, I'm not sure it will work or not. The solution does reduce the amount of cookies set to 1. I'm not big on using hooks, but after playing around for a couple hours, it's the only way I could do what I was trying to do. Hooks must be turned on in config/config. A post controller hook needs to be created in config/hooks.php. Please check it out and let me know if it works:
config/hooks.php
Code:
$hook['post_controller'][] = array(
'function' => 'finalize_session',
'filename' => 'finalize_session.php',
'filepath' => 'hooks'
);
MY_Session.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Session extends CI_Session {
private $cookie_data = array();
/**
* Write the session cookie
*
* @access public
* @return void
*/
public function _set_cookie($cookie_data = NULL)
{
if (is_null($cookie_data))
{
$cookie_data = $this->userdata;
}
// Serialize the userdata for the cookie
$cookie_data = $this->_serialize($cookie_data);
if ($this->sess_encrypt_cookie == TRUE)
{
$cookie_data = $this->CI->encrypt->encode($cookie_data);
}
else
{
// if encryption is not used, we provide an md5 hash to prevent userside tampering
$cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
}
$this->cookie_data[] = $cookie_data;
}
/**
* Finalize Session
*/
public function finalize_session()
{
if( ! empty( $this->cookie_data ) )
{
$cookie_data = array_pop( $this->cookie_data );
$expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
// Set the cookie
setcookie(
$this->sess_cookie_name,
$cookie_data,
$expire,
$this->cookie_path,
$this->cookie_domain,
$this->cookie_secure
);
$this->cookie_data = array();
}
}
// -----------------------------------------------------------------------
}
/* End of file MY_Session.php */
/* Location: ./application/libraries/MY_Session.php */
hooks/finalize_session.php
Code:
<?php
function finalize_session()
{
$CI =& get_instance();
$CI->session->finalize_session();
}
In my testing, when sending ajax responses, I had to change how I would normally send my response. Normally I just echo json_encode( $response ); I found I had to use Output:
et_output() instead.
Code:
// echo json_encode( $response );
$this->output->set_output( json_encode( $response ) );