Welcome Guest, Not a member yet? Register   Sign In
CI Reactor 2.0.1 Session Class. Data does not get passed.
#1

[eluser]Maikh85[/eluser]
Hi there,

CI's session library has got me pulling my hair out by now. For some weird reason the session data I am setting does not get passed to any next function within the controller.

Where I'm setting the session vars, all is fine. A var_dump shows the variables and their values being correctly set. However, at any other function I call thereafter, all variables have disappeared.

Code:
<?php

function one() {
$this->session->set_userdata(array('test'=>'val');
}

function two() {
var_dump($this->session->userdata);
}

?>

I did some searching and I read it could have to do with $config['cookie_domain'] in the config file. But even when I set that one, I get a session reset. On every page reload the ["session_id"] is reset as well, should this happen?

Hope someone can help me out on this.. Thanks in advance.

EDIT:
This is my config.php on sessions:
Code:
$config['sess_cookie_name']        = 'cisession';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']    = FALSE;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300;

Tried to use db session storage, but that made no difference.
#2

[eluser]Maikh85[/eluser]
When using the db to store sessions, they do get stored, but session data is not picked up thereafter.

Examples below. Session class is autoloaded.

Code:
public function ses1()
    {
        $this->load->library(array('input', 'form_validation'));
        echo '<pre>';
        var_dump($this->session->set_userdata('test', 'test'));
        var_dump($this->session->userdata);
    }
Outputs:
Code:
NULL
array(5) {
  ["session_id"]=>
  string(32) "bee594f249ac90160e066781ef551f95"
  ["ip_address"]=>
  string(12) "86.92.219.xx"
  ["user_agent"]=>
  string(50) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2."
  ["last_activity"]=>
  int(1302015845)
  ["test"]=>
  string(4) "test"
}



Code:
public function ses2()
    {
        $this->load->library(array('input', 'form_validation'));
        echo '<pre>';
        var_dump($this->session->userdata);
        
    }
Outputs:
Code:
array(4) {
  ["session_id"]=>
  string(32) "344a99b1b302f674715290ef2b34f712"
  ["ip_address"]=>
  string(12) "86.92.219.xx"
  ["user_agent"]=>
  string(50) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2."
  ["last_activity"]=>
  int(1302015849)
}
#3

[eluser]InsiteFX[/eluser]
Wrong! you need to pass the session userdata item you want to retrive!
Code:
public function ses2()
{
    $this->load->library(array('input', 'form_validation'));
    echo '<pre>';
    var_dump($this->session->userdata('test'));
        
}

InsiteFX
#4

[eluser]Maikh85[/eluser]
Hi InsiteFX,

Unfortunately,
Code:
public function ses2()
    {
        echo '<pre>';
        var_dump($this->session->userdata('test'));
    }

Gives me:
Code:
bool(false)
#5

[eluser]WanWizard[/eluser]
This sounds like your browser doesn't accept the session cookie.

What your your config's cookie settings? Which browser are you using?

Check your local browser settings to see if cookies are blocked, and use the browser tools available to check if the cookie is stored, and if so, what it contains.
#6

[eluser]InsiteFX[/eluser]
Like WanWizard stated above your browser must not be saving the cookie!

What browser our you testing with?

InsiteFX
#7

[eluser]Maikh85[/eluser]
Tested it with Firefox 4.0, Chrome 10.0.6 and Safari 5.0.4 and they all returned the same result.

I've uploaded my test application, see it here: http://www.leidsekoorprojecten.nl/ideal/
#8

[eluser]Maikh85[/eluser]
[quote author="WanWizard" date="1302036369"]This sounds like your browser doesn't accept the session cookie.

What your your config's cookie settings? Which browser are you using?

Check your local browser settings to see if cookies are blocked, and use the browser tools available to check if the cookie is stored, and if so, what it contains.[/quote]

My current config settings are:
Code:
$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']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "leidsekoorprojecten.nl";
$config['cookie_path']        = "/";
$config['cookie_secure']    = true;

$config['global_xss_filtering'] = true;
#9

[eluser]InsiteFX[/eluser]
Did you create the ci_session database table?

InsiteFX
#10

[eluser]Maikh85[/eluser]
[quote author="InsiteFX" date="1302040426"]Did you create the ci_session database table?

InsiteFX[/quote]

Yes I did. And data is stored there as well, but it seems it's not being used when requested by another function inside my controller.

It looks as if a whole new session object is being created instead of returning the earlier set one.




Theme © iAndrew 2016 - Forum software by © MyBB