Note that there are some explanatory texts on larger screens.

plurals
  1. POsimplexml_load_file and $_SESSION
    text
    copied!<p>I have a problem using simplexml_load_file and session vars in PHP.</p> <p>So, I have 2 PHP files, one generates some XML and the other one reads it. The file that generates XML should read some $_SESSION vars, which had been set in the other, but it won't...</p> <p>For instance, say the first file is something like:</p> <p>FILE 1 (reads XML)</p> <pre><code>&lt;? session_start(); $_SESSION['test'] = 'test!!!'; echo '&lt;b&gt;In file 1&lt;/b&gt;&lt;br /&gt;'; echo 'var = '.$_SESSION['test'].'&lt;br /&gt;'; // This correctly outputs "test!!!" echo '&lt;b&gt;Reading file 2&lt;/b&gt;&lt;br /&gt;'; $xml = simplexml_load_file("http://www.someurl.com/2.php"); echo 'var = '.$xml['var']; // This does &lt;b&gt;NOT&lt;/b&gt; output "test!!!"... why? ?&gt; </code></pre> <p>FILE 2 (generates XML)</p> <pre><code>&lt;? header('Content-type:application/xml'); session_start(); echo '&lt;?xml version="1.0" encoding="utf-8"?&gt;'; echo '&lt;test&gt;'; echo '&lt;var&gt;'.$_SESSION['test'].'&lt;/var&gt;'; echo '&lt;/test&gt;'; ?&gt; </code></pre> <p>The strange thing is, if I open file 2 directly it DOES read $_SESSION["test"]</p> <p>Things I already tried (and did not work)</p> <ul> <li><p>Not calling session_start() in the second file</p></li> <li><p>Calling session_write_close() before simplexml_load_file in the first file</p></li> <li><p>Accessing the file using fsockopen instead of simplexml_load_file. This also returns an empty tag... so it's not an issue with simplexml_load_file...</p></li> </ul> <p>I'm a bit out of ideas... can anyone help?</p> <p>Thanks nico</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload