Page 1 of 1

converting session data into variables

Posted: Mon Oct 27, 2003 10:00 am
by Marco Polo I
ok, my problem is next:
i dont want to use session_start, i simply want to read content from file into $var, then i want to convert $var content into variables


1. $path_to_session_file = tmp\sessions\sess_dfc5c25b2f21a808c2e060fc0f878d8e
";

$f = file_get_contents($path_to_session_file);



if i make print_r($f);
if seee serialized content of session_variables

now i try to make unserialize on this var = $f but this dont helps.

can anybody something to advice to me ?????


thanks,.....

Posted: Mon Oct 27, 2003 10:56 am
by Stoker
what does this output:

$mysess = unserialize ($f);
var_dump($mysess);

If it is FALSE it means the serialized string was not valid...

If you are looking for a way to make those vars a part of the current symbol table, try extract(unserialize($f))

...

Posted: Tue Oct 28, 2003 1:28 am
by Marco Polo I
1) here is my session
$fp = "C:\sess_041c46ab6c3e97f6bbcb7ec8de631ddb";

2) now i get all content of session file into string
$ff=file_get_contents($fp);

if i type print_r($ff); then i see this

mdat|a:5:{s:9:"fusername";s:8:"darconi8";s:9:"fmemberof";i:2;s:8:"fbannews";i:0;s:5:"fauth";i:1;s:8:"msession";s:32:"dinaburg49c1dc8d163decae1f471d8d";}url|s:3:"lp0";razdel|i:0;language|s:3:"rus";ovner|s:14:"VHALS-DINABURG";head|s:130:"";nomerlast|i:250;nomerprev|i:251;gdd|s:2:"21";gdm|s:1:"9";gdy|s:4:"2003";gazeta_date|s:25:"воскресение, 21 сентябрья";nomerlastdate|s:10:"09/21/2003";

3) now i try to unserialize this output
$ff = unserialize($ff);
var_dump($ff);

then if i type print_r($ff);

i see bool(false)

what this means ????



thanks for helping

Posted: Tue Oct 28, 2003 4:20 am
by JAM
This might get you started. Run this on a single page, and you'll understand what it shows you. However, I'm not sure it's good practice to do it like this in reallife.

Code: Select all

<?php
    echo '<pre>';
    $string = 'foo|s:3:"bar";bar|s:3:"foo";foofoo|s:6:"barbar";barbar|s:6:"foofoo";';
    $string = substr($string,0,-1); // strip the last ;
    $string = explode(';',$string); // explode the main ones
    print_r($string); // debug
    foreach($string as $value) {
        $newstring = explode('|',$value);
        echo '<hr />';
        foreach ($newstring as $parts) {
            $x = explode(':',$parts);
            print_r($x);
        }
    }
?>

Posted: Tue Oct 28, 2003 7:57 am
by Stoker
As I wrote in my first post, FALSE means the input is not valid, your data was not stored or received right.
I see no reason to manually analyze the string the way Jam is suggesting (what is that for? a serialized string is descriptors/attributes/content, not a bunch of values).

Where is the beginning "mdat|" in your string coming from Marco? I don't think that is supposed to be there, or there are missing stuff... Take a look at your storage procedure

A complete serialized array could look like this:
a:2:{i:0;s:5:"hello";i:1;s:3:"hey";}

Posted: Tue Oct 28, 2003 7:22 pm
by JAM
Stoker wrote:what is that for?
Are you asking me?

...

His string translated (looks wierd tho):

Code: Select all

Array
(
    &#1111;mdat] => Array
        (
            &#1111;fusername] => darconi8
            &#1111;fmemberof] => 2
            &#1111;fbannews] => 0
            &#1111;fauth] => 1
            &#1111;msession] => dinaburg49c1dc8d163decae1f471d8d
        )

    &#1111;url] => lp0
    &#1111;razdel] => 0
    &#1111;language] => rus
    &#1111;ovner] => VHALS-DINABURG
    &#1111;head] => ";nomerlast|i:250;nomerprev|i:251;gdd|s:2:"21";gdm|s:1:"9";gdy|s:4:"2003";gazeta_date|s:25:"&#1074;&#1086;&#1089;&#1082;&#1088;
    &#1111;7;&#1089;&#1077;&#1085;&#1080;&#1077;, 21 &#1089;&#1077;&#1085;&#1090;&#1103;&#1073;&#1088;&#1100;&#1103;";nomerlastdate] => 09/21/2003
)