drew22
asked on
unserializing session data without creating new session
I'm trying to create a session browser that will allow me to inspect sessions in my session table.
I found this function somewhere to convert session data to an array, but it only works with variables in the session, not arrays in the session
function sess_string_to_array($sd)
{
$sess_array = array();
$vars = preg_split('/[;}]/', $sd);
for ($i=0; $i < sizeof($vars); $i++)
{
$parts = explode('|', $vars[$i]);
$key = $parts[0];
$val = unserialize($parts[1].";") ;
$sess_array[$key] = $val;
}
return $sess_array;
}
I found this function somewhere to convert session data to an array, but it only works with variables in the session, not arrays in the session
function sess_string_to_array($sd)
{
$sess_array = array();
$vars = preg_split('/[;}]/', $sd);
for ($i=0; $i < sizeof($vars); $i++)
{
$parts = explode('|', $vars[$i]);
$key = $parts[0];
$val = unserialize($parts[1].";")
$sess_array[$key] = $val;
}
return $sess_array;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
are you using windows? On my linux-box where I tried it, it worked perfect (including an object)
ASKER
I'll try it again. Did you try it with session data containing arrays?
Yes, I tried it with an objects that contained an array and additional array:
e.g.
sessionreg|s:7:"Orc_RIP";S ESSIONID|s :15:"10989 78095.8022 ";RIP|a:3: {s:10:"inp utmulti";a :1:{s:4:"l ink";a:1:{ s:6:"param s";s:90:". /inputdata multi.php? cmd=edit&c lass=Colle ction&SESS IONID=1098 978095.802 2&Collecti on=100109" ;}}s:6:"br unch";a:2: {s:7:"show all";a:1:{ s:6:"PathI D";a:2:{i: 0;s:8:"030 10103";i:1 ;s:10:"030 1010301";} }s:10:"sho wbranch";a :1:{s:6:"P athID";a:4 :{i:0;s:8: "03010103" ;i:1;s:6:" 030101";i: 2;s:4:"030 1";i:3;s:1 0:"0301010 301";}}}s: 9:"DataPoi nt";a:3:{i :67;a:20:. ...
var_dump(of that function returned:
array(4) {
["sessionreg"]=>
string(7) "Orc_RIP"
["SESSIONID"]=>
string(15) "1098978095.8022"
["RIP"]=>
array(3) {
["inputmulti"]=>
array(1) {
["link"]=>
array(1) {
["params"]=>
string(90) "./inputdatamulti.php?cmd= edit&class =Collectio n&SESSIONI D=10989780 95.8022&Co llection=1 00109"
}
}
["brunch"]=>
array(2) {
["showall"]=>
array(1) {
["PathID"]=>
array(2) {
[0]=>
string(8) "03010103"
[1]=>
string(10) "0301010301"
}
}
.....
e.g.
sessionreg|s:7:"Orc_RIP";S
var_dump(of that function returned:
array(4) {
["sessionreg"]=>
string(7) "Orc_RIP"
["SESSIONID"]=>
string(15) "1098978095.8022"
["RIP"]=>
array(3) {
["inputmulti"]=>
array(1) {
["link"]=>
array(1) {
["params"]=>
string(90) "./inputdatamulti.php?cmd=
}
}
["brunch"]=>
array(2) {
["showall"]=>
array(1) {
["PathID"]=>
array(2) {
[0]=>
string(8) "03010103"
[1]=>
string(10) "0301010301"
}
}
.....
ASKER
Didn't work for me.
I might try http://www.evilwalrus.com/viewcode.php?codeEx=553 , but it is huge, and I can always manually extract arrays via this hard-coded:
$ar_name = 'completed|'
$p1 = strpos($sess_data, $ar_name');
$p2 = strpos($sess_data, ';}',$p1);
$s= substr($sess_data,$p1+strl
$completed = unserialize($s);