Jump to content

Recommended Posts

hi folks,

 

i know this should be simple, and i've sifted through the documentation and other posts on this for a fix, but i am merely a newbie and thus can't get it to work:

 

i'm trying to get the contents of URLs, but i get 404 errors for 99% of them, with a "failure to open stream" message.

 

php.ini has "allow_url_fopen = On" in it.

 

so why does this not work?

$contents = file_get_contents($url);

 

thanks very much in advance for any help!

 

best,

m

 

Link to comment
https://forums.phpfreaks.com/topic/106774-http-404-not-foundfailed-to-open-stream/
Share on other sites

here's a more complete look at my implementation:

 

$sites = file("sites.txt");

foreach ($sites as $url) {

echo $url,"\n";

$contents = file_get_contents($url);

}

 

sites.txt lists URLs, which are returned by echo looking like:

http://www.xyz.com/

 

are those properly formatted for file_get_contents?

 

the URLs i'm using are a variety of blogs, so it seems unlikely that there would be some kind of blocking going on for all them.

 

because i'm not seeing any details of an http request, i'm assuming that one is going on under the hood... would this need to be accessed and refined? 

might any other wrappers need to be enabled or altered?

 

thanks!

it works if i type in a string directly, e.g.

file_get_contents("http://www.site.com");

 

but not if i pass a string variable to the same function, e.g.

file_get_contents($sites[0]);

 

i'm getting my strings from a .txt file, storing them in an array, then passing each array member string as an argument to file_get_contents, but i still get:

"HTTP request failed! HTTP/1.1 404 Not Found"

 

anybody?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.