Welcome Guest, Not a member yet? Register   Sign In
Losing session data
#1

[eluser]Unknown[/eluser]
Hi

I've have this problem with the session and i can't wrap my head around it.

Each time I grab data from a link and put it in a session, the session data gets lost when i return to the controller using a link or a form from within the View.

This is the case:

i'm trying to store an id number in a database session. I pass the data through a link like this:

/admin/project/id/3

I grab the number from the link with $this->uri->segment(4) or just pass i through the function as a parameter.

function id($project_id)
{
$newdata = array(
'project_group_id' => $project_id
);

$this->session->set_userdata($newdata);
$this->overview();
}

function overview($param = array())
{
if(is_array($param))
{
foreach($param AS $key=>$value)
{
$data[$key] = $value;
}
}

$data['project_group_data'] = $this->project_model->get_all_groups();
$data['project_data'] = $this->project_model->get_project_data_by_id($this->project_group_id);
$data['load_page'] = 'admin/project_view';
$data['page_title'] = 'Projects';
$data['username'] = $this->session->userdata('username');

$this->load->view('admin/include/template', $data);
}

In the View, the session data is still traceable by var_dump() and with print_r(). But when i look in the database session, the data has changed to 'resources'.

var_dump($this->session->userdata):
array(7) {
["session_id"]=>
string(32) "582048e72c8a871d49e7fded35903229"
["ip_address"]=>
string(7) "0.0.0.0"
["user_agent"]=>
string(50) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; "
["last_activity"]=>
string(10) "1267801510"
["username"]=>
string(4) "Derk"
["is_logged_in"]=>
string(1) "1"
["project_group_id"]=>
string(1) "3"

}

print_r($this->session->userdata):
Array
(
[session_id] => 582048e72c8a871d49e7fded35903229
[ip_address] => 0.0.0.0
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2;
[last_activity] => 1267801510
[username] => Derk
[is_logged_in] => 1
[project_group_id] => 3
)

database session:
a:3:{s:8:"username";s:4:"Derk";s:12:"is_logged_in";s:1:"1";s:16:"project_group_id";s:9:"resources";}

When i go back to the controller using a link or form, all the project_group_data is set to 'resources'.

var_dump($this->session->userdata):
array(7) {
["session_id"]=>
string(32) "9bbdb190935837ef8cf631c7b35eed28"
["ip_address"]=>
string(7) "0.0.0.0"
["user_agent"]=>
string(50) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; "
["last_activity"]=>
int(1267801943)
["username"]=>
string(4) "Derk"
["is_logged_in"]=>
string(1) "1"
["project_group_id"]=>
string(9) "resources"

}

print_r($this->session->userdata):
Array
(
[session_id] => 582048e72c8a871d49e7fded35903229
[ip_address] => 0.0.0.0
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2;
[last_activity] => 1267801510
[username] => Derk
[is_logged_in] => 1
[project_group_id] => resources
)


When i put some hardcoded data in the session like 'test' the data stays untouched.
So it seems dat the problem occures with dynamic data passes through from controller->controller & controller->view->controller.

Any suggestions, ideas.

Cheers,
Derk
#2

[eluser]billmce[/eluser]
I seem to be experiencing the same problem.
I'm saving a search string in session data and using with pagination.
The session data is maintained in the original controller function (index) and the views it calls.

However when returning to the function after editing ... the session data is lost.
#3

[eluser]billmce[/eluser]
Interest, I solved my problem by changing from cookies to the database method of storing session info.
I made no other changes ... everything works.

Hours down the drain on that issue.

Seems that if you're using cookies, the session data is lost when the original function is reload.
#4

[eluser]InsiteFX[/eluser]
Read this...

set_flashdata

Enjoy
InsiteFX
#5

[eluser]billmce[/eluser]
I wasn't using flash_data, I was using session.
I wanted the data to be available beyond "the next server request" -- so I used session.

I don't follow how using flash_data would've helped.
#6

[eluser]InsiteFX[/eluser]
Your session could be timing out ad regerating a new session_id

Check your session timeout.

You may also need to unserialize the session data.
If you look at your session data above it is serialized.

Enjoy
InsiteFX
#7

[eluser]David BoreaNaz[/eluser]
[quote author="billmce" date="1269302443"]Interest, I solved my problem by changing from cookies to the database method of storing session info.
I made no other changes ... everything works.

Hours down the drain on that issue.

Seems that if you're using cookies, the session data is lost when the original function is reload.[/quote]

hi! may i butt in?
i also experience losing session data...
what is the database you are using?
i am trying to do this CI sessions + oracle database...
i hope someone can help me with this...
#8

[eluser]InsiteFX[/eluser]
Usally it is the timeout settings in the session
applications/config/config.php

Look at the seesion config

Also if your running IE it doe's not like the underscore
char so rename the cookie for ci_session to cisession.

I also rename the CI session database to cisesson.

Enjoy
InsiteFX
#9

[eluser]David BoreaNaz[/eluser]
Thanks, InsiteFX...
I'll try your suggestions..
I have set those variables prior to using Oracle database...
Like I said, when I used MySQL before - I have no problems with the session. I mean, if I log in, and click links to other pages on my site, my session cookie is there... When I switched to Oracle, there goes my problems...
Code:
$config['sess_cookie_name']    = 'ci_session';
$config['sess_expiration']    = 3600;
$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']    = TRUE;
$config['sess_time_to_update']     = 600;
#10

[eluser]David BoreaNaz[/eluser]
by the way, I have also set the variables on the Session.php controller, to mimic those that are on my config.php.....

class CI_Session {

var $sess_encrypt_cookie = TRUE;
var $sess_use_database = TRUE;
var $sess_table_name = 'ci_sessions';

$sess_expiration = 3600;
var $sess_match_ip = TRUE;
var $sess_match_useragent= TRUE;
var $sess_cookie_name = 'ci_session';

var $cookie_prefix = '';
var $cookie_path = '';
var $cookie_domain = '';
var $sess_time_to_update = 600;

hmmnnn.... these ones, I only set at a later date. Because I just noticed them there... I hope it does me no harm... or headache should I say. Sad




Theme © iAndrew 2016 - Forum software by © MyBB