0

I'm trying to call simplexml_load_file with the $url parameter being another .php file which will then make some calculations, and after that, it will "echo" a string containing the xml code.

It looks something like this:

$urlrequest= $_SERVER['DOCUMENT_ROOT']."/generateXML.php?id=5&output=xml";
$xml = simplexml_load_file($urlrequest);

where generateXML.php will be something like:

<?php

//do some random code

$aux= '<?xml version="1.0" encoding="UTF-8" ?>'; 
$aux.= "<item>";
$aux.= "<name>John</name>";
$aux.= "<location>somewhere</location>";
$aux.= "</item>";

echo $aux;
?>

The problem is, if generateXML.php is located at a remote ip it will work fine, but when the file is located in the same server, the i get the "failed to load external entity" error.

I have found out that the problem may come from the parameters in the url. For example:

$var1=file('dosomething.php'); works fine

but $var1=file('dosomething.php?id=1'); returns "failed to open stream" error

I need to be able to add those parameters to the url, is there any way of doing it?

EVL
  • 53
  • 3
  • 7

2 Answers2

1

It doesn't look like the problem is with allow-url-fopen because you said it works fine on a remote server.
What URL are you calling to access your local server? Maybe try to avoid names like http://localhost/something.php and use IP addesses only like http://127.0.0.1/something.php.

martin
  • 93,354
  • 25
  • 191
  • 226
  • As you said, allow-url-fopen cant be the problem because the problem doesnt appear when calling an external ip, and i already checked that it is ON in php.ini – EVL Mar 08 '13 at 15:03
0

if the argument is an URL, PHP will make a socket request, so check your PHP.ini settings, example this one http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

but it's probably more elegant and faster to load the script that generate the XML by including the script directly with the parameters, otherwise wou are basically only stressing your webserver with an useless additional request

E Ciotti
  • 4,740
  • 1
  • 25
  • 17