Welcome Guest, Not a member yet? Register   Sign In
where is field for session data in database
#1

[eluser]section31[/eluser]
I was looking at CI's session library and I don't see a field in the table structure to put the serialized array data in there.

Code:
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
PRIMARY KEY (session_id)
);

Correct me if I'm wrong, but I thought the whole reason for using a database as opposed to a cookie is for storing the actual session data into the database?

Also, if I wanted to use php's native sessions, where would be the best place to call session_start() if I want it used throughout the site.
#2

[eluser]sophistry[/eluser]
i think you might be expecting CI sessions class to store the session data actually in the db table ci_sessions?

as you have astutely observed, it does not do that. session ids are managed through the db and the data is serialized and stored in cookies using the sess_write() function of the Session class:
Code:
/**
     * Write the session cookie
     *
     * @access    public
     * @return    void
     */
    function sess_write()
    {                                
        $cookie_data = serialize($this->userdata);
        
        if ($this->encryption == TRUE)
        {
            $cookie_data = $this->CI->encrypt->encode($cookie_data);
        }
        else
        {
            // if encryption is not used, we provide an md5 hash to prevent userside tampering
            $cookie_data = $cookie_data . md5($cookie_data.$this->CI->config->item('encryption_key'));
        }

        setcookie(
                    $this->sess_cookie,
                    $cookie_data,
                    $this->sess_length + time(),
                    $this->CI->config->item('cookie_path'),
                    $this->CI->config->item('cookie_domain'),
                    0
                );
    }

best place to call sessions_start()? i would think index.php... but i have never done that. i recall that the wiki hosts some alternative session libraries...

cheers.
#3

[eluser]section31[/eluser]
Thanks for the reply.

I don't see any benefits of using a database if the real data isn't stored in there. Why was this not developed into the library?
#4

[eluser]Colin Williams[/eluser]
Grab the DB_Session Library from the Wiki. It does exactly what you're thinking. We can spend 5 pages of thread discussing whether or not it should be (have been) in CI if you want, but it's not. The contributed library works fantastically.
#5

[eluser]beemr[/eluser]
If you guys are operating from the svn, 1.6.4 now writes userdata to the ci_sessions table instead of the cookie.




Theme © iAndrew 2016 - Forum software by © MyBB