[eluser]Unknown[/eluser]
Hey guys !
I was banging my head into the wall this morning because i couldn't figure out what was the problem.
I have a huge session array (i know, it's bad but I REALLY can't do anything else) with some arrays in it.
This is a dumbed down version of what I have :
Code:
$user = array('name' => 'name',
'downloads' => array('url' => 'http://www.perdu.com', 'name' => 'something\with\blackslashes')
);
The problem was that when serializing the array, the part with the \es wasn't processed and thus causing the _unserialize method to crash. Of course i do addslashes to my datas.
So i changed the code a little to add some recusivity in it :
Code:
function _serialize($data)
{
if (is_array($data))
{
//EDITED PART
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);
}
Now everything is working correctly.
Going through all the session process (database, serialize, unserialze, test for special characters...) was a real pain.