views:

432

answers:

3

I am trying to read an XML-file from another server. However the the company that's hosting me seems to have turned of the file_get_contents function from retrieving files for files from other servers (and their support is not very bright and it takes forever for them to answer). So I need a work around in some way.

This is my current code

 $url =  urldecode( $object_list_url );
 $xmlstr = file_get_contents ( $url );
 $obj = new SimpleXMLElement ( $xmlstr, LIBXML_NOCDATA );
A: 

The ini var you're referring to is allow_url_fopen. To check, run this script:

var_dump(ini_get('allow_url_fopen'));

Ask your host to turn that ini value on (if it's disabled - it's on by default).

You should not be able to access any remote url without that ini setting on.

Also an idea if they won't could be to try copying the file to your server. I expect all filesystem functions will be covered by that ini setting but it's always worth a try.

Ross
+7  A: 

You could use cURL (if that's not been disabled). Something like this:

$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$xmlstr = curl_exec($c);
Greg
Apparently allow_url_fopen doesn't cover cURL so this might be your best bet.
Ross
I would recommend cURL too - it's much more reliable and secure than allow_url_fopen.
Eli
http://wiki.dreamhost.com/CURL#Alternative_for_file_get_contents.28.29
Gilean
Hmm good answer tried some of the stuff in the link I seem to be getting a "CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir"-warning/error, other than that it seems I get a "Object moved to here"-message. Is this fixable?
Reed Richards
Got it working. The problem was the location header of the file I was requesting was pointing to another file, setting the CURLOPT_FOLLOWLOCATION didn't work because of security. So what I did was taking the URL of the file pointed at by the header and adding it to cURL. Ugly solution but it works.
Reed Richards
A: 

Can you execute the following script and provide the information as a comment?

<?php
phpinfo();
?>
jakemcgraw
Won't fit in the 300 characters...but cURL is turned on.
Reed Richards