简体   繁体   中英

how to store xml obj in php session variable

First (to supress the flamers) This link does not answer my question - a minimum it was not helpful Storing XML object in PHP Session Variables

The following WAS a little more helpful as, unlike the above, gave an example

Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed'

I tried that, did not work.

$obj = simplexml_load_string(path/to/xml/file)
$_SESSION[somevar] = $obj

Using this elsewhere produced an exception error which led me to the above link. More research says that you cannot store xml in a php session var, if this is true, is there a way to use it from page to page. The record I pull from my xml files are small, so sql would be an over kill. But for the curious,

  • I want to
  • expanding my knowledge of xml
  • and learning about dynamics.
  • project is very small

the script just pulls one game record with a dozen fields, then uses the info to display on a page. The pages are accessed dynamically so various pages do diferent things with the data.

one idea I have is: would it be worth while to create a function to call the record when needed and manipulate it from there?

ps If this is a moot question or annoying one, please do not answer - I searched for many hours yesterday, and I was disappointed by the sarcasm in many of the responses given, responses that either did not answer the question, or they themselves asked the OP questions that did not pertain to the question - this clutters up SO for us looking for answers. I did do some research, and finally here to check with those that are knowledgeable and may shed some light on a different angle.

Thanks

您可以改为保存对象的序列化字符串$ xml-> asXML();。

//set $_SESSION['xml'] = $xml->asXML(); //get $xml = new SimpleXMLElement($_SESSION['xml']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM