Welcome Guest, Not a member yet? Register   Sign In
losing session data
#8

[eluser]St0neyx[/eluser]
[quote author="InsiteFX" date="1290784081"]WanWizard is right!

You must not have read the Session Class!

Because if you did you would know that the session class doe's not
store the user_data in the cookie!

InsiteFX[/quote]

The user guide says that yes, but when i started testing it i came to different outcome.
So i opened Session.php (the library CI provides) to analyze the code.

Now just for fun look at this:
Code:
function set_userdata($newdata = array(), $newval = '')
{
    if (is_string($newdata))
    {
        $newdata = array($newdata => $newval);
    }

    if (count($newdata) > 0)
    {
        foreach ($newdata as $key => $val)
        {
            $this->userdata[$key] = $val;
        }
    }

    // write the session
    $this->sess_write();
}

function sess_write()
{
    // Are we saving custom data to the DB?  If not, all we do is update the cookie
    if ($this->sess_use_database === FALSE)
    {
        $this->_set_cookie();
        return;
    }

    // set the custom userdata, the session data we will set in a second
    $custom_userdata = $this->userdata;
    $cookie_userdata = array();

    // Before continuing, we need to determine if there is any custom data to deal with.
    // Let's determine this by removing the default indexes to see if there's anything left in the array
    // and set the session data while we're at it
    foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
    {
        unset($custom_userdata[$val]);
        $cookie_userdata[$val] = $this->userdata[$val];
    }

    // Did we find any custom data?  If not, we turn the empty array into a string
    // since there's no reason to serialize and store an empty array in the DB
    if (count($custom_userdata) === 0)
    {
        $custom_userdata = '';
    }
    else
    {
        // Serialize the custom data array so we can store it
        $custom_userdata = $this->_serialize($custom_userdata);
    }

    // Run the update query
    $this->CI->db->where('session_id', $this->userdata['session_id']);
    $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));

    // Write the cookie.  Notice that we manually pass the cookie data array to the
    // _set_cookie() function. Normally that function will store $this->userdata, but
    // in this case that array contains custom data, which we do not want in the cookie.
    $this->_set_cookie($cookie_userdata);
}

Now could you explain the last line of sess_write() to me? seems like it's writing an cookie...

So therefor i say, it still writes cookies..


Messages In This Thread
losing session data - by El Forum - 11-25-2010, 07:40 AM
losing session data - by El Forum - 11-25-2010, 08:42 AM
losing session data - by El Forum - 11-25-2010, 08:51 AM
losing session data - by El Forum - 11-25-2010, 10:31 AM
losing session data - by El Forum - 11-25-2010, 02:04 PM
losing session data - by El Forum - 11-26-2010, 02:09 AM
losing session data - by El Forum - 11-26-2010, 03:08 AM
losing session data - by El Forum - 11-26-2010, 03:21 AM
losing session data - by El Forum - 11-26-2010, 04:01 AM
losing session data - by El Forum - 11-26-2010, 05:28 AM
losing session data - by El Forum - 11-26-2010, 06:21 AM
losing session data - by El Forum - 11-26-2010, 06:45 AM
losing session data - by El Forum - 11-26-2010, 06:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB