Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange fopen problem

Status
Not open for further replies.

Patrick1327

IS-IT--Management
May 10, 2001
14
US
Hi, I have a strange problem. The fopen function (and fsocketopen and cURL) failes when trying to open an internet connection. If you open local file, it works fine.

Log gives an unable to connect / permission denied error. Turned off the firewall software on Linux (RH Fedora core 5) server and placed server in DMZ in router with no luck.

Code (works):

<?php
$fp = fopen("./some.file", "r");
if (!$fp) {
echo "fopen failure! \n";
}
fclose($fp);
?>


Code (fails):

<?php
$fp = fopen(" "r");
if (!$fp) {
echo "fopen failure! \n";
}
fclose($fp);
?>
 
PHP Manual said:
If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.
Did you check the status of the allow_url_open in your php.ini? This looks like it is disabled. You can read more about fopen() in the manual.
 
Thanks for he reply Vragabond, allow_url_open in php.ini is set On
 
do you still get the error if you pass a resource name too?
Code:
fopen("[URL unfurl="true"]http://www.cnn.com/index.html",[/URL] "r");

does this happen with all sites (it may be that cnn do some browser sniffing).
 
See if this makes a difference:
Code:
<?php
   $fp = file("[URL unfurl="true"]http://www.cnn.com");[/URL]
   if(!$fp) 
     echo "odd failure?! \n";
   else
     foreach($fp as $lineno => $line)
       echo $line;
?>

Regards
 
Patrick1327:
Just to ask the dumb question....

If you point your web browser to a script on your server, that script composed entirely of:

Code:
<?php
phpinfo();
?>

What does the output say about the settings for "allow_url_fopen" and "Configuration File (php.ini) Path"? I had a problem once where I was trying to reconfigure PHP and was editing the wrong copy of php.ini. Fought the problem for 5 hours before I discovered what I was doing wrong and felt like a complete idiot after my discovery.





Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top