Jump to content

http 404 not found/failed to open stream


alphalpha

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.