If you have a script using sessions, you might experience this error when working with PHP’s SimpleXML functions. PHP Warning: session_start(): Node no longer exists
. Here we will show you what the error message means and the simple solution for it.
Problem
Warning: session_start() [function.session-start]: Node no longer exists
This problem arises when you attempt to store xml data from SimpleXML extension in the session, as in the example below. PHP SimpleXML functions treat xml as a resource and it cannot be directly stored in the session.
$string = "<?xml version="1.0" encoding="ISO-8859-1"?><token>1234567890</token>"; $result = simplexml_load_string($string); //will not work $_SESSION['token'] = $result->token; |
Solution
The solution is simple! Simply cast your data into a different data type, like a string.
$string = "<?xml version="1.0" encoding="ISO-8859-1"?><token>1234567890</token>"; $result = simplexml_load_string($string); //works fine $_SESSION['token'] = (string)$result->token; |
Now you can store your xml values into the session. They can now be manipulated any way you want, such as building them back into a multi-dimensional array that it might have started as. If this tip helped you, leave a comment. Thanks!
Your tip worked absolutely perfect for me! Your simple code example made all the difference to clearly understand what was actually going wrong within my code. Thank you very much for making your fix available.
I was facing the same problem. Thankfully, I searched and found your page that gives me the solution too.
Thanks again.
Glad to help!
Your the man! Perfect solution!
Hi Thanks a lot, I was having same problem and your solution worked perfectly in my case. Thank you
Wow… thanks! Finally found a solution after troubleshooting for like 2 hours. Ugh. I mean thank you.
You are welcome, I know the feeling!
Thanks Very Much you saved alot of my time 🙂
Great, just what I needed!
Thank you for your solution, 🙂