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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 533k
  • Answers 533k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What do you mean by "connect it with wordpress using… May 17, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer Most modern std::string implementations1 save very small strings directly on… May 17, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer The most widely used documentation standard in the PHP world… May 17, 2026 at 12:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using the PHP SimpleXML way of working with XML files on my
I have a problem here using .dbf files. I can make CRUD operations but
I'm using simpleXML to parse this xml file . It's a feed I'm using
i have problem with simpleXml and adding new items. This is my xml: <?xml
I have a strange problem where a for loop in PHP only returns the
So I have a PHP file that I use to define all my constants
So to start, I have an array of XML files. These files need to
I am having some problems parsing this piece of XML using SimpleXML. There is
Hi I have problem using Shared Folder in VMare Fusion 3 and Visual Studio
i am coming back because i still have problem using JodaTime. After the previous

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.