CodeIgniter Forums
How works sessions ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How works sessions ? (/thread-52421.html)



How works sessions ? - El Forum - 06-10-2012

[eluser]Vadorequest[/eluser]
Hi,

I'm sorry for my bad english, I'm French.

I don't understand how works the CI sessions. (I autoload the 'session' library)

When I will change the current language in my website and the language used is invalid I do:
Code:
add_error('La langue sélectionnée est incorrecte ou non gérée.');

The add_error function is defined in helpers/error_helpers.php:
Code:
/**
* Add Error
*
* Add an error to the var error in CI session.
*
* @access  public
* @param string
* @param bool
*/
if ( ! function_exists('add_error'))
{
  function add_error($message, $displayed = false)
  {
    $CI =& get_instance();
    
    $errors = $CI->session->userdata('errors');

    if($errors == false){
      $errors = array();
    }
    $nbErrors = count($errors);
    $errors[$nbErrors]['message'] = $message;
    $errors[$nbErrors]['displayed'] = $displayed;
    
    $CI->session->set_userdata('errors', $errors);
  }
}

If I do
Code:
var_dump($CI->session->all_userdata());
at the final line (in add_error()) he displayed normally my sessions vars.

But, if after, in my view, I do:
Code:
&lt;?php $CI =& get_instance(); echo "<pre>";var_dump($CI->session->all_userdata());?&gt;

He displayed only the basic session data (user agent, etc.) others vars has been destroyed.

In my BDD I have:
session_id: f17c49e7aafa6734d03d5666ea01eeca
user_data: a:2:{s:9:"user_data";s:0:"";s:6:"errors";a:1:{i:0;a:2:{s:7:"message";s:55:"La langue sélectionnée est incorrecte ou non gérée.";s:9:"displayed";b:0;}}}

But the current session_id is not: f17c49e7aafa6734d03d5666ea01eeca

After every refresh my session_id changes. Normally ?

This my current config in config/config.php:
Code:
$config['sess_cookie_name']  = 'ci_session';
$config['sess_expiration']  = 0;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name']  = 'Vado_Session';
$config['sess_match_ip']  = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

Can you help me ? Thanks.


How works sessions ? - El Forum - 06-10-2012

[eluser]web-johnny[/eluser]
You have tho change the
Code:
$config['sess_expiration']  = 0;

to a numeric value. For example:
Code:
$config['sess_expiration']  = 500;




How works sessions ? - El Forum - 06-10-2012

[eluser]Vadorequest[/eluser]
In the doc (under $config):
| 'sess_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration.

I've 300 before but I've changed after, no change I think. I test again.


How works sessions ? - El Forum - 06-10-2012

[eluser]Vadorequest[/eluser]

$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
It's better as that ^^ Before I have config with vars but it's do a problem.

But I've always a problem... My BDD is updated with local session php but my vars in user_data as been destroyed >< user_data also.

Code:
array(4) {
  ["session_id"]=>
  string(32) "7c6ee3638580e9fe222c433b0531ccfd"
  ["ip_address"]=>
  string(9) "127.0.0.1"
  ["user_agent"]=>
  string(106) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"
  ["last_activity"]=>
  int(1339353883)
}

The key 'user_data' is not exists. But in BDD I've:
Code:
a:2:{s:9:"user_data";s:0:"";s:6:"errors";a:1:{i:0;a:3:{s:7:"message";s:46:"La langue sélectionnée n'est pas autorisée.";s:9:"displayed";b:0;s:4:"type";s:5:"error";}}}


If I do var_dump just after I've update the session php I have:
Code:
array(5) {
  ["session_id"]=>
  string(32) "7c6ee3638580e9fe222c433b0531ccfd"
  ["ip_address"]=>
  string(9) "127.0.0.1"
  ["user_agent"]=>
  string(106) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5"
  ["last_activity"]=>
  int(1339353883)
  ["errors"]=>
  array(1) {
    [0]=>
    array(3) {
      ["message"]=>
      string(46) "La langue sélectionnée n'est pas autorisée."
      ["displayed"]=>
      bool(false)
      ["type"]=>
      string(5) "error"
    }
  }
}

But my key 'errors' dissapear after a new load page.

Thanks for your help.