alphalpha Posted May 22, 2008 Share Posted May 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/106774-http-404-not-foundfailed-to-open-stream/ Share on other sites More sharing options...
ober Posted May 22, 2008 Share Posted May 22, 2008 It may be something on their end blocking it or something in the URL is screwed up. How are you getting $url filled? If you echo the $url var each time, is it returning a valid url? Quote Link to comment https://forums.phpfreaks.com/topic/106774-http-404-not-foundfailed-to-open-stream/#findComment-547332 Share on other sites More sharing options...
alphalpha Posted May 22, 2008 Author Share Posted May 22, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/106774-http-404-not-foundfailed-to-open-stream/#findComment-547337 Share on other sites More sharing options...
alphalpha Posted May 22, 2008 Author Share Posted May 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/106774-http-404-not-foundfailed-to-open-stream/#findComment-547492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.