4
votes

I am using Codeigniter 2.1.0 and CI_session for session handling.

I assume that this

  1. Page A sets some variables in the session using $this->session->set_userdata().
  2. Page A redirects to Page B
  3. Page B is expected to retain the session variables that were set in Page A.

However this is what happens to me

  1. Page A sets some variables in the session using $this->session->set_userdata().
  2. Page A redirects to Page B
  3. Page B does not retain the session variables that were set in Page A.

I have code in Page A to save and record the contents of $this->session->userdata in a log before redirection to Page B. The log shows that the values that are set in session exist.

However, using var_dump() on $this->session->userdata on Page B shows that those values don't exists.

I don't really know how this could be. I have double checked that I am not unsetting the values in Page B. It's like CI_Session is somehow unsetting them behind the scenes.

Any ideas?

EDIT: Yes, I am using the database to save session data. The field type is TEXT.

1
are you saving your session data to database...if not try saving the sessions data to database... $config['sess_use_database'] = TRUE;.. and check... - bipen
is it happening in all browsers? - Code Prank
Is it all the session data? or just some of it? If your session data is exceeding the size of the cookie restrictions, not all of it will be passed across. Try saving them to the database if your not already. - Jeemusu
@bipen I have updated my question to answer your question - developarvin
@ShayanHusaini Yes. It is happening to all browsers. - developarvin

1 Answers

1
votes

From what I understand from networks, the cookies and sessions are stored in client machine and not server. So HTTP basically adds cookies and sessions to your request headers and sends the request.

But in this case you are setting the sessions and then redirecting from the same page in server. Normal PHP might handle this differently but codeIgniter does not use native PHP sessions. (Refer http://ellislab.com/codeigniter/user-guide/libraries/sessions.html)

This is my guess. But it would be helpful if I take a look at your code.