Welcome Guest, Not a member yet? Register   Sign In
Session serialized data... kinda? Dont understand the format
#20

It sounds like you've gotten to a point where things are more complicated than they should be.

If I understand this correctly, you want to know which sessions are open for a given account_id. When the session library calls sess_regenerate(), it is essentially saying that the old session is closed and a new session has been opened using the existing data. So, when sess_regenerate() is called, you basically just need to notify your Accounts_model of this situation, which might be something like this:

PHP Code:
public function sess_regenerate($destroy FALSE)
{
    
$oldId session_id();
    
parent::sess_regenerate($destroy);
    
$newId session_id();

    if (! 
class_exists('accounts_model'false)) {
        
$this->load->model('accounts_model');
    }
    
$this->accounts_model->sessionRegenerate($oldId$newId);


How you handle this in your Accounts_model depends on how you're using the relations in the database, but you shouldn't need to touch the session. If you need to keep the entry with the $oldId value until a write occurs, then I would recommend adding a nullable column to your table for the $newId value. Then, in Accounts_model->sessionRegenerate(), you would update the entry with $oldId to add the $newId value to the new column, and insert a new entry with the $newId in the normal session column. Then, when the write occurs, you would notify the Accounts_model and it could go back through and delete the row with the $newId in the new column. If you have the potential for regenerating the session multiple times before writing the session, you would simply have to go back through the chain, finding the rows with each of the previous session IDs and deleting all of them.

If the Accounts_model doesn't access the session in its constructor, this won't be a problem. Further, the only thing the model should really do in terms of accessing the session is store/retrieve the account_id in the session. Any time you access the account_id in the model, it should be through get/set methods which access the session only when the value hasn't been retrieved (on get) or when it changes (on set). The session ID shouldn't be needed in the Accounts_model except for those relationships, so the session ID can be passed to the model from the session library or retrieved from the reference table.
Reply


Messages In This Thread
RE: Session serialized data... kinda? Dont understand the format - by mwhitney - 08-26-2015, 08:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB