• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lost session

[quote author="Derek Allard" date="1205368324"]Sessions are not readable until the next page load. If you moved to another controller, you should be able to see it.[/quote]

Man I had almost this EXACT same problem and this is the key! Judging by all the threads on this, I don't think many people know this, but thank you so much. This helped me a lot!

I had the same problem with userdata session in IE.

I have a library (Auth.php) where I checked the login and set a couple of userdata. After the redirect/refresh in the loginmodel my session in IE was lost in the next pages.

My solution was:
in the Auth.php I closed the session with session_write_close();

$this->session->set_userdata('mysession', 'myvalue');

Maybe it will help other people to solve the same problem.

So I discovered my real problem was that my array that I was trying to pass was too large. When I made it smaller all the data was retained. Not sure if there's a size restriction on session variables, but this solved my problem.

For cookie based sessions, the limit is the maximum size of the cookie, 4Kb. For database sessions, the size is only limited by the size of the user_data field.

In both cases, a serialized array is stored, so you need to calculate a couple of bytes extra (p.e. 10) for the type and length indicators.

session_write_close() is a PHP function, which doesn't have any meaning in CI (unless you use native sessions).

Generally I'm not a thread-gravedigger but I just stumbled upon this issue too while fiddling with UTF-8 chars in the session (cart) and got it fixed, jamesf was on the right way:

[quote author="jamesf" date="1272484444"]I was having the same issue and I believe it was caused by certain UTF-8 characters in the session. As a quick fix I used the base64_encode/base64_decode functions in the _serialize/_unserialize methods like this

It's definitely an UTF-8 encoding issue, but I didn't want to have base64 encoded Strings in my DB. You can also fix the Session.php class by adding utf8 en- and decoding like this (CI 2.0.1):

function _unserialize($data)
  $data = @unserialize(utf8_decode(strip_slashes($data)));


function _serialize($data)
  return utf8_encode(serialize($data));

Works like a charm and keeps your DB Sessions readable/debuggable.


I've always used UTF-8 in my CI projects, and I have yet to encounter any issue with it, including sessions.

You have to make sure though that the database you use is also configured to store and use UTF-8. If not, you'll get funny conversion problems which might be the case here.

please help me !!

My Session Data Not Set

codeigniter version: 2.0.0

in local no problem but in linux server PHP Version 5.2.17
my session data not set in IE and opera and safari Browser but Firefox is ok

in window server session set in IE and Firefox but linux not set

It is a bug?
I do not know

the classic session of php Good work

please help me!!!

this is sample code

class Sessiontest extends CI_Controller{
    function index(){
       $newdata = array(
                   'username'  => 'johndoe',
                   'email'     => 'johndoe@some-site.com',
                   'logged_in' => TRUE



class sessiontest2 extends CI_Controller{
    function index(){
       echo $this->session->userdata('username');
       echo $this->session->userdata('session_id');

[eluser]William Rufino[/eluser]
Well I'm losing session after redirects! :/

*duplicate* *please delete, admin*

From what I read in this thread, I managed to solve the session problem: in file config/config.php just rename the sess_cookie_name to something without underscore, ie. from 'ci_session' to 'cisession'. That worked for me. Cheers.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.