Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 632969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:08:03+00:00 2026-05-13T20:08:03+00:00

I have a problem using simplexml_load_file and session vars in PHP. So, I have

  • 0

I have a problem using simplexml_load_file and session vars in PHP.

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…

For instance, say the first file is something like:

FILE 1 (reads XML)

<?
session_start();
$_SESSION['test'] = 'test!!!';
echo '<b>In file 1</b><br />';
echo 'var = '.$_SESSION['test'].'<br />';  // This correctly outputs "test!!!"
echo '<b>Reading file 2</b><br />';
$xml = simplexml_load_file("http://www.someurl.com/2.php");
echo 'var = '.$xml['var'];                 // This does <b>NOT</b> output "test!!!"... why?
?>

FILE 2 (generates XML)

<?
header('Content-type:application/xml');
session_start();

echo '<?xml version="1.0" encoding="utf-8"?>';

echo '<test>';
echo '<var>'.$_SESSION['test'].'</var>';
echo '</test>';
?>

The strange thing is, if I open file 2 directly it DOES read $_SESSION[“test”]

Things I already tried (and did not work)

  • Not calling session_start() in the second file

  • Calling session_write_close() before simplexml_load_file in the first file

  • 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…

I’m a bit out of ideas… can anyone help?

Thanks
nico

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:08:03+00:00Added an answer on May 13, 2026 at 8:08 pm

    From a user/browser point of view, the session is passed from page to page via a cookie that contains the session identifier.

    A bit like this :

    • page 1 creates a session and send the cookie containing its identifier to the browser
    • the browser requests page 2 and send the cookie with its request
    • the server sees that cookie ; it allows it to load the session
    • page 2 is sent, alongside the cookie, that will be re-used for other pages

    Here, you have two pages, but the session identifier is not passed from file 1 to file 2 — which means file 2 doesn’t even know there is an existing session.

    In fact, you have two clients, here :

    • for file 1, the client is the guy using his browser
      • who is the one with the session
    • for file 2, the client is file 1
      • who doesn’t have a session identifier
      • hence, is another user, who doesn’t share the session of the guy using his browser
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a perfectly working XML parser using PHP... using, $xml = simplexml_load_file($newfile);
I'm trying to parse some XML using simpleXML in PHP. The problem I'm having
I am using the PHP SimpleXML way of working with XML files on my
I am trying to read an XML file using LINQ. I have had no
I have a problem when using simplexml to read a xml document that I
I'll be using PHP to parse a SVG-file and I've done some tests with
I'm having trouble getting the XML from a file using the simplexml_load_file function. I
I'm trying to parse a moderately large XML file (6mb) in php using simpleXML.
I have a xml feed with some html in one of my nodes. So
I am using Visual Studio 2010 and I have a simple XML file which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.