PHP function not working from switch

software development

#1

I just signed up for dreamhost earlier today, in the process of moving my site over I came across this error.

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/.squirm/kblessing/thebokeh.com/functions.php on line 163

the second line of the next pasting is line 163

$xml_file = “http://www.thebokeh.com/rss.php”;
$data = XML_unserialize(file_get_contents($xml_file));

Is file_get_contents disabled by the hosting, it was working on my previous, and I need to be able to read the response of the url as a string.

-Karl Blessing


#2

Karl,

file_get_contents itself is not disabled, but url access via that function is disabled as a security function.

There is a good workaround in the use of cURL, and you can find an example specific to your needs in this DH wiki article on cURL.

[quote]Alternative for file_get_contents()

Instead of:

<?php $file_contents = file_get_contents('http://example.com/'); // display file echo $file_contents; ?>

Use this:

<?php $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, 'http://example.com'); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); // display file echo $file_contents; ?>

Otherwise if you are getting some errors with the code above, use this:

<?php $site_url = 'http://example.com'; $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $site_url); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); ob_start(); curl_exec($ch); curl_close($ch); $file_contents = ob_get_contents(); ob_end_clean(); echo $file_contents; ?>[/quote]

–rlparker


#3

Thanks for the information

-Karl Blessing


#4

You are welcome!

–rlparker