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!