Welcome Guest, Not a member yet? Register   Sign In
session bug serializer
#1

[eluser]Unknown[/eluser]
hey i just joined codeigniter and nearly understand the entire framework core yesterday and i already found bugs on the session object against database anyway i solved this hope this will help others.


Code:
/**
     * Serialize an array
     *
     * This function first converts any slashes found in the array to a temporary
     * marker, so when it gets unserialized the slashes will be preserved
     *
     * @access    private
     * @param    array
     * @return    string
     */
    function _serialize($data)
    {
        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                if(!is_object($val)) $data[$key] = str_replace('\\', '{{slash}}', $val);
            }
        }
        else
        {
            $data = str_replace('\\', '{{slash}}', $data);
        }

        return serialize($data);
    }

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

    /**
     * Unserialize
     *
     * This function unserializes a data string, then converts any
     * temporary slash markers back to actual slashes
     *
     * @access    private
     * @param    array
     * @return    string
     */

    function _unserialize($data)
    {
        $data = @unserialize(strip_slashes($data));

        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                if(!is_object($val) && is_string($val))
                $data[$key] = str_replace('{{slash}}', '\\', $val);
            }

            return $data;
        }

        return str_replace('{{slash}}', '\\', $data);
    }


searching on forum founded such similiar case above but do note one thing,

if you autoloaded session and then u try to access the object thats being serialize
and you load your object manually without autoloading you'll recieve uncomplete php class.

to solve it , you got to manually load session after you load all the objects that your accessing, so,

Code:
$this->load->library("session");
$this->load->library("Entities/object1");
$obj1 = new object1();
$this->session->set_userdata("obj1",$obj1);

Will work if setting

Code:
$this->load->library("Entities/object1");
$this->load->library("session");
$obj1 = $this->session->userdata("obj1");

Will work

Code:
$this->load->library("session");
$this->load->library("Entities/object1");
$obj1 = $this->session->userdata("obj1");

this will not work

i hope you guys do solve this automatically when session is being called in the autoloader so i can freely manually load my own objects that are stored in the session,
since this is a wonderful framework = )




Theme © iAndrew 2016 - Forum software by © MyBB