2

I am trying to get the (pre-processed) content of an external PHP file:

file_get_contents('http://www.example.org/myfile.php');

When I do this, I get an error:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Applications/XAMPP/xamppfiles/htdocs/...localfile.php on line 13

And:

Warning: file_get_contents(http://www.example.org/myfile.php) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /Applications/XAMPP/xamppfiles/htdocs/.../localfile.php on line 13

Any ideas what I could do?

Thanks in advance!

EDIT: I do have allow_url_fopen set to "On".

3
  • do you have allow_url_fopen = On in your php.ini?
    – jay.lee
    Sep 26, 2010 at 11:45
  • 2
    This is most likely a DNS issue.
    – racetrack
    Sep 26, 2010 at 11:46
  • 1
    You could be in safe_mode which disables allow_url_fopen too, use cURL instead.
    – Cups
    Sep 26, 2010 at 13:42

1 Answer 1

4

You can probably use cURL...

function curl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $return = curl_exec($ch);
    curl_close ($ch);
    return $return;
}


$string = curl('http://www.example.org/myfile.php'); //string with data
2
  • Thanks, I'll try out whether it works - as soon as I can :D By the way: curl_close($ch) is an unreachable statement ^^
    – arik
    Sep 26, 2010 at 19:26
  • 1
    No it's not :) Only exit() will terminate function. Sep 27, 2010 at 7:41

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.