EllisLab text mark
Advanced Search
     
Getting data from session table
Posted: 05 November 2012 11:42 AM
Joined: 2012-10-15
77 posts

Hi,

I would like to get a join between session_table and user_table based on the fact that user_table.id is equal to session_table.userdata.user_id where the last_activity is less than 1 minute. I have problem so far in getting the user_id from userdata and I tried to insert a column user_id in the session_table but the system do not update the field automaticaly.

 

 
Posted: 06 November 2012 03:33 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

User data is stored as a string, a result of the serialize() function. If you want the session library to update new, proprietary columns, then you’ll need to extend and modify the library to do so. That functionality is not built-in.

 
Posted: 06 November 2012 03:43 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-10-15
77 posts

I was looking this thread

How to add user_id to sesssion table (previous)

But it does not work anymore for the current version of the library.

I add the following line in sess_write()

if (isset($this->userdata['user_id'])) {
                        $user_id 
$this->userdata['user_id'];
                
else {
                        $user_id 
'';
                
}  

  
// 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,'user_id'=>$user_id)); 
 
Posted: 06 November 2012 03:48 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

I don’t see why that wouldn’t work. Make sure your session table’s structure has been updated, and that your user ID is being set properly to the session userdata array.

And show any specific errors if you’re receiving any.

 
Posted: 06 November 2012 04:12 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-10-15
77 posts

I’m sure the user_id is set properly because it is stored in the serialized userdata.

The table structure… do you mean I have to specify the structure outside the method sess_write()? Or do you mean if add the column in the database, because the latter i did.

 
Posted: 06 November 2012 04:29 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

I meant add the column to the DB. However, you should make sure that the user_id column either allows NULL, or add a default value, since sess_create() will perform a DB insert.

You’ll have to be more specific about what’s not working, though, if that doesn’t help.

 
Posted: 06 November 2012 04:43 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-10-15
77 posts

It is difficult to be more precise, because actually the debug does not give me the possibility to check what is going on inside Session. Any way the system add the default value of the field.

 
Posted: 06 November 2012 05:00 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2012-10-15
77 posts

I solved. It was a stupid error I made. When i went changing the Session file I made a copy and i setted it in the wrongest place i could : The library of the application folder. I don’t know why just because it seemed the place better named. hmmm

Thanks.