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

(This post was last modified: 08-27-2015, 12:32 PM by jLinux.)

I ended up using debug_backtrace() to see which function was calling it... Seems to work..


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
MY_Session_database_driver extends CI_Session_database_driver {

 
   public function write($session_id$session_data)
 
   {
 
       if( ! parent::write($session_id$session_data))
 
           return FALSE;

 
       // If theres an account ID set in the session data...
 
       if (isset($_SESSION['account_id']))
 
           Accounts_model::account_session_assoc();

 
       return TRUE;
 
   }

 
   public function gc($maxlifetime)
 
   {
 
       if( ! parent::gc($maxlifetime))
 
           return FALSE;
 
       
        return $this
->_assoc_gc();
 
   }

 
   public function destroy($session_id)
 
   {
 
       if( ! parent::destroy($session_id))
 
           return FALSE;
 
       
        return $this
->_assoc_gc();
 
   }


 
   private function _assoc_gc()
 
   {

 
       $backtrace debug_backtrace(2);

 
       // Check if this was executed by destroy or sessio regeneration
 
       if(@$backtrace[2]['function'] === 'session_regenerate_id')  // session_destroy = Logout or cleanup; session_regenerate_id = Regeneration
 
           return TRUE;
 
       

        $sess_query 
$this->_db->select('id')->from('ci_sessions')->get();
 
       
        $sess_result 
$sess_query->result();


 
       if(count($sess_result) === 0)
 
           return TRUE;

 
       $sessions = array();

 
       foreach($sess_result as $s)
 
           array_push($sessions$s->id);
 
       
        return $this
->_db->where_not_in('session_id'$sessions)->delete('account_sessions_assoc');
 
   }


If theres any CI best practices that I violated, lmk ;-)
Reply


Messages In This Thread
RE: Session serialized data... kinda? Dont understand the format - by jLinux - 08-27-2015, 11:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB