• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where is field for session data in database

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.

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.

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:
     * 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);
            // 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'));

                    $this->sess_length + time(),

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...


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?

[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.

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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