CodeIgniter Forums
[Solved][Session] Not holding data - 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: [Solved][Session] Not holding data (/thread-22158.html)



[Solved][Session] Not holding data - El Forum - 08-31-2009

[eluser]Clooner[/eluser]
I'm trying to save some data as a session with the session class but with every page refresh the data gets lost.

Code:
$this->data['basket_key']=$this->session->userdata('basket_key');
if (!$this->data['basket_key'])
{
    $this->data['basket_key']=uniqid();
    $this->session->set_userdata('basket_key',$this->data['basket_key']);
}

And this is my config
Code:
$config['cookie_path']   = "/";
$config['cookie_domain'] = str_replace('/','',str_replace('http://',"",$config['base_url']));
$config['cookie_prefix'] = "InScortaC_";
$config['sess_cookie_name']        = 'inscorta_session';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']  = 0;

I don't see a reason for the sessions getting lost. The value "basket_key" gets regenerated every page refresh but I should remember it. I have the feeling I'm using the session class in a wrong way but in any case I'm a bit lost on what is going on here.


[Solved][Session] Not holding data - El Forum - 08-31-2009

[eluser]wabu[/eluser]
It looks like you have some custom config settings. Have you tried it with the default settings?

Otherwise I'd suggest breaking the problem into smaller steps or a simpler test case to make sure everything's working (if you haven't already).


[Solved][Session] Not holding data - El Forum - 08-31-2009

[eluser]Clooner[/eluser]
[quote author="wabu" date="1251751695"]It looks like you have some custom config settings. Have you tried it with the default settings?

Otherwise I'd suggest breaking the problem into smaller steps or a simpler test case to make sure everything's working (if you haven't already).[/quote] Good Idea! going back to basics but unfortinarlly it still looses the basket_key after several refreshes. I tried it with several browsers but every time the same problem.


[Solved][Session] Not holding data - El Forum - 08-31-2009

[eluser]Clooner[/eluser]
It seems that I have it working now. My cookie_domain setting was incorrect. It seems that I needed to add a .(dot) to the domain and not include the subdomains. With the basic config it also doesn't work because here the domain is not set.