Forum Moderators: coopster

Message Too Old, No Replies

file get contents() error

         

rjbearcan

12:31 am on Aug 14, 2006 (gmt 0)

10+ Year Member



I made a PHP5 script that uses the file_get_contents() funtion and when I run the script, I get this error:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration

I called my host up and they said that it is a coding error, not a security or server error,

Here is the code:

<?php
$address = "http://www.example.com";
echo htmlspecialchars(file_get_contents($address));
?>

jatar_k

5:24 pm on Aug 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well I doubt they are right

maybe try a phpinfo [php.net] file and see the setting of allow_url_open [php.net]

rjbearcan

5:14 am on Aug 15, 2006 (gmt 0)

10+ Year Member



OK...I figured out my problem which hasn't led to any solution:

What I am trying to do is extract XML values using PHP. I can use the file_get_contents() function in a regular .php file yet when I combine that with a SimpleXMLElement function in a .php5 script, I get the previously mentioned error.

Here is my nightmare:

file1.php

<?php
$address = "http://www.address.to/xmlfile";
$page = htmlspecialchars(file_get_contents($address));
echo $page;
?>

This gives me a page with all the xml file info, though it isn't a properly formatted xml page, it just looks like text, is that what should have happened?

Anyway, I know that file_get_contents works just fine with php4, but that SimpleXMLElement is only in PHP5, so I created another file:

file2.php5

<?php
include 'file1.php';
$xml = new SimpleXMLElement($page);
?>

This is what gives me the error I mentioned before, the:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration

Why is the file_get_contents function screwing up file2.php5?

rjbearcan

3:13 am on Aug 16, 2006 (gmt 0)

10+ Year Member



I've tried other examples that just use file_get_contents() in PHP5 and get the same error, yet my host says that it's a coding issue. Is this something that can be changed via .htaccess?

rjbearcan

3:39 am on Aug 16, 2006 (gmt 0)

10+ Year Member



Problem solved: allow_url_fopen wasn't turned on in php.ini which was quickly solved.