iwarlord Posted October 23, 2009 Share Posted October 23, 2009 I'm having some problems using file_get_contents on my local server. $text= file_get_contents("file.php"); works fine as expected but... $text= file_get_contents("file.php?id=1"); ...throws a warning "Warning: file_get_contents(file.php?id=1) [function.file-get-contents]: failed to open stream: No error". Putting the url in a browser works correctly though. Obvious it has to do with the get request but... $text= file_get_contents("http://www.google.com/search?hl=en&q=bpatterson&btnG=Google+Search"); ...works like it should. I tried using the full URL of file.php but then I get failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. . Also, no luck with using the full file path from root. I tried url_encode which gave me failed to open stream: No such file and a 403 error when using the encoded url in a browser. I guess maybe its a server config problem??? but I wouldn't know what to change. Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/ Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 I'm not certain, but it could be something todo with the allow_url_fopen option in your php.ini, do you know what this value is set to? Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942793 Share on other sites More sharing options...
iwarlord Posted October 23, 2009 Author Share Posted October 23, 2009 allow_url_fopen = On Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942809 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 That's not the problem then, oh well worth a shot. Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942818 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2009 Share Posted October 23, 2009 I tried using the full URL of file.php Post what you tried. xxxxxx out any sensitive information in the URL, but don't change any of the syntax. Also, does file.php use sessions or cookies to allow access to it? Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942826 Share on other sites More sharing options...
iwarlord Posted October 23, 2009 Author Share Posted October 23, 2009 Aha! I've got it working. I was using "http://localhost" but replaced it with "http://ipaddress" and it works fine now. Should the full URL be necessary in this case or is something still not setup right? Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942844 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2009 Share Posted October 23, 2009 Should the full URL be necessary in this case Yes, a GET parameter only has meaning and only works on the end of the URL, not on the end of a file name. Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942849 Share on other sites More sharing options...
iwarlord Posted October 23, 2009 Author Share Posted October 23, 2009 'course it does! Great stuff, cheers. Just me having a thick day:) Quote Link to comment https://forums.phpfreaks.com/topic/178728-solved-file_get_contents-with-get-request/#findComment-942851 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.