Solved

simplexml_load_file --> HTTP request problem

Posted on 2008-10-24
8
1,453 Views
Last Modified: 2012-08-14
Hi,

I have a strange problem. I am using php to get data from a xml file.
It all worked, but suddenly it doesn't anymore. The XML url is correct.
Triple-checked the url.

Although the file used to work, when i made a copy of it and uploaded it, this error
also appeared. So my initial thought was that the (remote) server only allowed
this file to connect. My host has recently upgraded to php5.
BTW : allow_url_fopen = on.

Anyone with bright ideas? Thanks in advance.

I get  this error (replaced the urls with fake ones).:

Warning: simplexml_load_file(http://www.url.com/index.php?ID=2&ww=aaa&freq=all&land=world&actie=all) [function.simplexml-load-file]: failed to open stream: HTTP request failed! in /home/users/etc/file.php on line 42

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.url.com/index.php?ID=2&ww=aaa&freq=all&land=world&actie=all" in /home/users/etc/file.php on line 42

Warning: Invalid argument supplied for foreach() in /home/users/etc/file.php on line 43
0
Comment
Question by:dwax
  • 4
  • 4
8 Comments
 

Author Comment

by:dwax
ID: 22794934

Some more info: my ISP has  simplexml_load_file enabled.
Now i am thinking that the server where the XML is located has a user agent check of some sort,
if i acces the file via a browser it works, via .php it gives the error.

0
 
LVL 6

Expert Comment

by:fourice
ID: 22794942
Is it possible that due to the update the server doesn't allow a script to access the file (see the user_agent setting in php.ini).
Possible solution could be setting this manually:
user_agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
0
 
LVL 6

Expert Comment

by:fourice
ID: 22794957
You last reply wasn't there when I opened the thread. But we are thinking the same.
0
 

Author Comment

by:dwax
ID: 22795041
Thanks fourice:

I was looking into setting the user agent in the php file that calls the XML,
but how do i implement this in .php?

Something like this?
header("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 6

Expert Comment

by:fourice
ID: 22795096
Try:
ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

0
 

Author Comment

by:dwax
ID: 22795355

Thanks, this:
header("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

Also seemed to do the trick, BUT:

i found out that if the XML is big, the 404 just comes back.
Could it be that the host is limiting the amount of data or something like that?
0
 
LVL 6

Accepted Solution

by:
fourice earned 250 total points
ID: 22798336
I doubt that a limit on the amount of data will give you a 404...
But just in case you could try adding:
ini_set("max_execution_time", 0);
ini_set("memory_limit", "10000M");
0
 

Author Comment

by:dwax
ID: 22948572
Whoopsidaisy, that does the trick!
Thanks fourice!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now