Welcome Guest, Not a member yet? Register   Sign In
Cannot unserialize ci_sessions from database
#3

(04-10-2015, 03:45 AM)InsiteFX Wrote: In CI 3.0 it doe's not look like they are using the unserialize and serialize methods anymore.

Best to look at the session class to see what's going on.

I try to looking CI_Session_database_driver.php, and I found Serialized session data
But I still don't understand  Sad
I've poor skill of PHP

PHP Code:
/**
     * Read
     *
     * Reads session data and acquires a lock
     *
     * @param    string    $session_id    Session ID
     * @return    string    Serialized session data
     */
    
public function read($session_id)
    {
        if (
$this->_get_lock($session_id) !== FALSE)
        {
            
// Needed by write() to detect session_regenerate_id() calls
            
$this->_session_id $session_id;

            
$this->_db
                
->select('data')
                ->
from($this->_config['save_path'])
                ->
where('id'$session_id);

            if (
$this->_config['match_ip'])
            {
                
$this->_db->where('ip_address'$_SERVER['REMOTE_ADDR']);
            }

            if ((
$result $this->_db->get()->row()) === NULL)
            {
                
$this->_fingerprint md5('');
                return 
'';
            }

            
// PostgreSQL's variant of a BLOB datatype is Bytea, which is a
            // PITA to work with, so we use base64-encoded data in a TEXT
            // field instead.
            
$result = ($this->_platform === 'postgre')
                ? 
base64_decode(rtrim($result->data))
                : 
$result->data;

            
$this->_fingerprint md5($result);
            
$this->_row_exists TRUE;
            return 
$result;
        }

        
$this->_fingerprint md5('');
        return 
'';
    }

    
// ------------------------------------------------------------------------

    /**
     * Write
     *
     * Writes (create / update) session data
     *
     * @param    string    $session_id    Session ID
     * @param    string    $session_data    Serialized session data
     * @return    bool
     */
    
public function write($session_id$session_data)
    {
        
// Was the ID regenerated?
        
if ($session_id !== $this->_session_id)
        {
            if ( ! 
$this->_release_lock() OR ! $this->_get_lock($session_id))
            {
                return 
FALSE;
            }

            
$this->_row_exists FALSE;
            
$this->_session_id $session_id;
        }
        elseif (
$this->_lock === FALSE)
        {
            return 
FALSE;
        }

        if (
$this->_row_exists === FALSE)
        {
            
$insert_data = array(
                
'id' => $session_id,
                
'ip_address' => $_SERVER['REMOTE_ADDR'],
                
'timestamp' => time(),
                
'data' => ($this->_platform === 'postgre' base64_encode($session_data) : $session_data)
            );

            if (
$this->_db->insert($this->_config['save_path'], $insert_data))
            {
                
$this->_fingerprint md5($session_data);
                return 
$this->_row_exists TRUE;
            }

            return 
FALSE;
        }

        
$this->_db->where('id'$session_id);
        if (
$this->_config['match_ip'])
        {
            
$this->_db->where('ip_address'$_SERVER['REMOTE_ADDR']);
        }

        
$update_data = array('timestamp' => time());
        if (
$this->_fingerprint !== md5($session_data))
        {
            
$update_data['data'] = ($this->_platform === 'postgre')
                ? 
base64_encode($session_data)
                : 
$session_data;
        }

        if (
$this->_db->update($this->_config['save_path'], $update_data))
        {
            
$this->_fingerprint md5($session_data);
            return 
TRUE;
        }

        return 
FALSE;
    }

    
// ------------------------------------------------------------------------ 
Reply


Messages In This Thread
RE: Cannot unserialize ci_sessions from database - by pudyastoadi - 04-10-2015, 04:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB