views:

57

answers:

1

Hello, I'm having some trouble using sessions with php.. I think I have figured out why, it seems that when I set the session variable it is copying the entire SimpleXMLElement object rather than just the value stored in said object. How can I make sure to just store the value in my session variable??

Here are some code snippets:

$records = $listingNums->RecordCount->Returned[0];
$_SESSION['test'] = 'green';
$_SESSION['saleRecords'] = $records;
for($x=0;$x<count($listingNums->ListingNumber);$x++){
    $_SESSION['saleNumbers'][$x] = $listingNums->ListingNumber[$x];
}

So if I dump the session variables out just after setting them, they seem ok. But when i come back into the page, they are not set. The test = green I set trying to see if I could get any session variables working, and that one does save to the next page.

My session save path is writable and it writes out the following:

test|s:5:"green";saleRecords|O:16:"SimpleXMLElement":1:{i:0;s:1:"6";}saleNumbers|a:6:{i:0;O:16:"SimpleXMLElement":1:{i:0;s:7:"2736176";}i:1;O:16:"SimpleXMLElement":1:{i:0;s:7:"2733979";}i:2;O:16:"SimpleXMLElement":1:{i:0;s:7:"2733522";}i:3;O:16:"SimpleXMLElement":1:{i:0;s:7:"2715680";}i:4;O:16:"SimpleXMLElement":1:{i:0;s:7:"2708179";}i:5;O:16:"SimpleXMLElement":1:{i:0;s:7:"2673739";}}

Also the Session is remembered and the variables are set when I come back into the page, but other than the test one they appear empty.

I hope thats enough info and I'd really appreciate any help!

Thanks!

Christine

A: 

Untested answer, but you could either convert it to xml, or convert it to string

As string (and converted records to array as well):

$records = $listingNums->RecordCount->Returned[0];
$_SESSION['test'] = 'green';
$_SESSION['saleRecords'] = (array)$records;
for($x=0;$x<count($listingNums->ListingNumber);$x++){
    $_SESSION['saleNumbers'][$x] = (string)$listingNums->ListingNumber[$x];
}

As XML:

$records = $listingNums->RecordCount->Returned[0];
$_SESSION['test'] = 'green';
$_SESSION['saleRecords'] = (array)$records;
for($x=0;$x<count($listingNums->ListingNumber);$x++){
    $_SESSION['saleNumbers'][$x] = $listingNums->ListingNumber[$x]->asXML();
}
halkeye
Thank-you! That was so simple :) thank you so much for a quick answer!
christine