Shinu Thomas
Shinu Thomas

Reputation: 5316

Session is not working while Parsing SimpleXMLElement Object

I get one array, when i am parsing a xml file using xpath xquery.The array is this

Array
    (
        [0] => SimpleXMLElement Object
            (
                [userid] => 2
                [username] => UserName
                [userpassword] => 40bd001563085fc35165329ea1ff5c5ecbdbbeef
                [usertype] => A
                [createdBy] => 1
            )

    )

I want to store the userid in a session variale.I created this

if(!empty($nodes))
{
  foreach($nodes as $node)
  {
   $UserId=$node->userid;
  }
}
$_SESSION['UserId1']= $UserId; 

Inside the foreach the session is getting.But if i run the page again am getting

Warning: session_start() [function.session-start]: Node no longer exists

and the session is not getting.Can anybody give a solution

Upvotes: 0

Views: 372

Answers (1)

2ndkauboy
2ndkauboy

Reputation: 9397

You tried to store the reference to a node from your SimpleXML object. But you have to store the content of this node instead. To do this, simply cast it to a string:

$UserId = (string)$node->userid;

Upvotes: 5

Related Questions