Welcome Guest, Not a member yet? Register   Sign In
Extend CI_Session_database_driver to work with extra cols in ci_sessions table
#4

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

The following doesnt seem to work. I inserted a log_message() just to see if it would log, and tailed the logs, it didnt log it at all.. Am I doing this right? Still sorta new to CI

File: application/core/MY_Session_database_driver.php
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)
    {
        
log_message('error',"SESSTEST: TEST SESSION WRITE: {$session_id}");
        
// 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;
    }



Renamed thread to a more descriptive title
Reply


Messages In This Thread
RE: Extra column in sessions table - by Narf - 08-19-2015, 11:20 AM
RE: Extra column in sessions table - by jLinux - 08-19-2015, 11:33 AM
RE: Extra column in sessions table - by jLinux - 08-19-2015, 12:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB