Welcome Guest, Not a member yet? Register   Sign In
custom My_Session
#1

I am working on MongoDB Session driver:
Now I get these error:
Quote:A PHP Error was encountered

Severity: Notice

Message: Indirect modification of overloaded property MY_Session::$CI has no effect

Filename: Session/MY_Session.php

Line Number: 32

Backtrace:

File: C:\wamp\www\application\libraries\Session\MY_Session.php
Line: 32
Function: _error_handler

File: C:\wamp\www\index.php
Line: 292
Function: require_once

( ! ) Fatal error: Cannot assign by reference to overloaded object in C:\wamp\www\application\libraries\Session\MY_Session.php on line 32
Call Stack
# Time Memory Function Location
1 0.0020 148464 {main}( ) ..\index.php:0
2 0.0080 193512 require_once( 'C:\wamp\www\system\core\CodeIgniter.php' ) ..\index.php:292
3 0.1160 855896 CI_Controller->__construct( ) ..\CodeIgniter.php:500
4 0.1230 992056 CI_Loader->initialize( ) ..\Controller.php:79
5 0.1230 992168 CI_Loader->_ci_autoloader( ) ..\Loader.php:157
6 0.1250 993928 CI_Loader->library( ) ..\Loader.php:1324
7 0.1430 1198824 CI_Loader->library( ) ..\Loader.php:202
8 0.1430 1198856 CI_Loader->_ci_load_library( ) ..\Loader.php:218
9 0.1440 1199128 CI_Loader->_ci_load_library( ) ..\Loader.php:1048
10 0.1470 1199384 CI_Loader->_ci_load_stock_library( ) ..\Loader.php:1003
11 0.1530 1330816 CI_Loader->_ci_init_library( ) ..\Loader.php:1140
12 0.1550 1331440 MY_Session->__construct( ) ..\Loader.php:1247
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\wamp\www\application\libraries\Session\MY_Session.php:32)

Filename: core/Common.php

Line Number: 573

Backtrace:
A PHP Error was encountered

Severity: Error

Message: Cannot assign by reference to overloaded object

Filename: Session/MY_Session.php

Line Number: 32

Backtrace:
And my code is:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter MongoDB Library
*
* A library to interact with the NoSQL database MongoDB.
* For more information see http://www.mongodb.org
*
* @package        CodeIgniter
* @author        Alessandro Arnodo | [email protected] | @vesparny
* @copyright    Copyright (c) 2012, Alessandro Arnodo.
* @license        http://www.opensource.org/licenses/mit-license.php
* @link
* @version        Version 1.1.0
*
*/

/**
* MY_Session
*
* Override core methods in order to write sessions data on MongoDB.
* Use this class only if you want to store session data on db.
* @since v1.1
*/
class MY_Session extends CI_Session {

    protected $sess_use_mongo = FALSE;
    protected $sess_collection_name = FALSE;

    public function __construct($rules = array())
    {
        log_message('debug', '*** Hello from MY_Session ***');
        $this->CI =& get_instance();
        $this->CI->load->config('cimongo');
        $this->sess_use_mongo = $this->CI->config->item('sess_use_mongo');
        $this->sess_collection_name = $this->CI->config->item('sess_collection_name');
        $this->CI->load->library("cimongo/cimongo");
        parent::__construct();
            
    }

    /**
     * Fetch the current session data if it exists
     *
     * @access    public
     * @return    bool
     */
    function sess_read()
    {
        // Fetch the cookie
        $session = $this->CI->input->cookie($this->sess_cookie_name);

        // No cookie?  Goodbye cruel world!...
        if ($session === FALSE)
        {
            log_message('debug', 'A session cookie was not found.');
            return FALSE;
        }

        // Decrypt the cookie data
        if ($this->sess_encrypt_cookie == TRUE)
        {
            $session = $this->CI->encrypt->decode($session);
        }
        else
        {
            // encryption was not used, so we need to check the md5 hash
            $hash     = substr($session, strlen($session)-32); // get last 32 chars
            $session = substr($session, 0, strlen($session)-32);

            // Does the md5 hash match?  This is to prevent manipulation of session data in userspace
            if ($hash !==  md5($session.$this->encryption_key))
            {
                log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
                $this->sess_destroy();
                return FALSE;
            }
        }

        // Unserialize the session array
        $session = $this->_unserialize($session);

        // Is the session data we unserialized an array with the correct format?
        if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity']))
        {
            $this->sess_destroy();
            return FALSE;
        }

        // Is the session current?
        if (($session['last_activity'] + $this->sess_expiration) < $this->now)
        {
            $this->sess_destroy();
            return FALSE;
        }

        // Does the IP Match?
        if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address())
        {
            $this->sess_destroy();
            return FALSE;
        }

        // Does the User Agent Match?
        if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120)))
        {
            $this->sess_destroy();
            return FALSE;
        }

        // Is there a corresponding session in the DB?
        if ($this->sess_use_mongo === TRUE)
        {
            $this->CI->cimongo->where(array('session_id'=>$session['session_id']));

            if ($this->sess_match_ip == TRUE)
            {
                $this->CI->cimongo->where(array('ip_address'=>$session['ip_address']));
            }

            if ($this->sess_match_useragent == TRUE)
            {
                $this->CI->cimongo->where(array('user_agent'=>$session['user_agent']));
            }

            $query = $this->CI->cimongo->get($this->sess_collection_name);

            // No result?  Kill it!
            if ($query->num_rows() == 0)
            {
                $this->sess_destroy();
                return FALSE;
            }
How can I fix it?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB