jgutierrez Posted December 21, 2007 Share Posted December 21, 2007 Hello all, I am running php 5.2.4 and 4.3.9 on the same machine that uses the same php.ini file. I run php 5.2.4 by doing the following at the command line: [jgutierrez@jgutierrez] php5 <script_name> and I run php 4.3.9 by doing the following [jgutierrez@jgutierrez] php <script_name> I am using 5.2.4 and trying use fopen() to fetch a web page. However, when I call fopen() with a url I get the following warning: Warning: fopen(<url>): failed to open stream: No such file or directory. I checked the php.ini file to see if the variable "allow_url_fopen" is set to "On" and it is. I can call fopen() on a different machine running 5.2.3-1 and I get the requested page. Is there something that I am missing? Any help/suggestions would be greatly appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/ Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 it says you dont have that file try to filter it first using http://www.php.net/manual/en/function.file-exists.php Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420092 Share on other sites More sharing options...
jgutierrez Posted December 21, 2007 Author Share Posted December 21, 2007 Thanks for the reply. I am not trying to use fopen() to open a file. I am using it to open a web page. Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420101 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 can we see your code? Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420105 Share on other sites More sharing options...
jgutierrez Posted December 21, 2007 Author Share Posted December 21, 2007 Note: I had to alter the url because I am posting to a gateway owned by a billing company and the url is specific to my company. <?php $url = "https://someurl.com/api/?name=SERVICE&version=1.0&clientid=001&user_id=A001&password=password"; $http_handle = fopen($url, "r"); $response_contents = fread($http_handle, 512); print_r($response_contents . "\n"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420117 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 $handle = fopen("http://www.phpfreaks.com/forums/index.php/topic,173024.0.html", "rb"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); echo $contents; try that and replace the url Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420132 Share on other sites More sharing options...
jgutierrez Posted December 21, 2007 Author Share Posted December 21, 2007 Hmm...the call to fopen() yields the same warning. Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420161 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 can you access that page using url alone ? Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420163 Share on other sites More sharing options...
jgutierrez Posted December 21, 2007 Author Share Posted December 21, 2007 Yes Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420169 Share on other sites More sharing options...
teng84 Posted December 21, 2007 Share Posted December 21, 2007 Yes then there should you should be fine? does the script i gave you work using the phpfreak as url? Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420172 Share on other sites More sharing options...
jgutierrez Posted December 21, 2007 Author Share Posted December 21, 2007 Using the phpfreaks url worked. However, the url I am using uses https protocol, not http. Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420199 Share on other sites More sharing options...
rarebit Posted December 21, 2007 Share Posted December 21, 2007 http://uk3.php.net/manual/en/function.fopen.php Warning When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To workaround this, you should lower your error_reporting level not to include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning for you. If you are using fsockopen() to create an ssl:// socket, you are responsible for detecting and suppressing the warning yourself. Further down is this, http://uk3.php.net/manual/en/function.fopen.php#58099 Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420265 Share on other sites More sharing options...
dewey_witt Posted December 21, 2007 Share Posted December 21, 2007 Try This..... <?php $data=file("https:\\www.someurl.com\htmlpage.html"); foreach ($data as $l => $r) { echo $r; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82610-fopen-urls/#findComment-420269 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.