-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CodeIgniter Session Cannot Store/Retrieve Multi-dimensional Array Data #1562
Comments
For now I'm using this as a work-around courtesy of the CodeIgniter forum: <?php
class MY_Session extends CI_Session
{
function __construct($config = array())
{
parent::__construct($config);
}
/**
* 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))
{
array_walk_recursive($data, function(&$item,$key){
if (is_string($item))
{
$item = str_replace('\\', '{{slash}}', $item);
}
});
}
else
{
if (is_string($data))
{
$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))
{
array_walk_recursive($data, function(&$item,$key){
if (is_string($item))
{
$item = str_replace('{{slash}}', '\\', $item);
}
});
return $data;
}
return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
}
} |
@EllisLab Why don't you add this fix in to current stable version? |
@LONGMANi If you want the code to be added I suggest creating a pull request :) |
A PHP 5.2-compatible version of the shown work-around already is present in the develop branch. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The functions below result in data loss when handling multi-dimensional arrays
Session::_serialize()
Session::_unserialize()
The $app_status array will not be available in the session data when the function below is called later from a different controller or url
This prevents CI's Session from being a drop-in replacement for PHP's native $_SESSION handler
The text was updated successfully, but these errors were encountered: