Re: PHP 4.0 Bug #8552 Updated: fopen doesn't open URL
| From: | Stig Venaas | Date: | Fri, 05 Jan 2001 08:00:20 +0000 |
| Subject: | Re: PHP 4.0 Bug #8552 Updated: fopen doesn't open URL | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-43012@lists.php.net to get a copy of this message | ||
On Thu, Jan 04, 2001 at 03:44:52PM -0700, Zak Greant wrote:
> Stig Venaas wrote:
> > On Thu, Jan 04, 2001 at 03:12:55PM -0700, Zak Greant wrote:
> > > Hi Stig,
> > >
> > > I can confirm this behavior on my Win2k box running PHP 4.0.4/IIS
> > >
> > > fopen ("http://www.yahoo.com/",
> > > "r"); // Works
> > > fopen ("http://yahoo.com/", "r");
> > > // Fails
> >
> > I think that bug is something different, I think yahoo.com fails
> > because fopen doesn't handle redirects. Of course the success
> > error is no good, the reason for that is that fopen gives the
> > error of the last system call, but the redirect doesn't cause a
> > system call failure. I'll fix it so it gives a better error
> > message or so it handles redirects.
I've checked further, it seems to me that redirects was supported (at
least it looks that way) until October 13. It seems that when the
http wrapper was put into ext/standard/http_fopen_wrapper.c, the
following ifdef was added:
#if 0
if (location[0] != '\0') {
return php_fopen_url_wrapper(location, mode, options, issock, socketd,
opened_path);
} else {
return NULL;
}
#else
return NULL;
#endif
I'm wondering why.
Another thing though, the HTTP header is stored in $http_response_header
after the fopen call, for instance:
$fp = fopen("http://yahoo.com/", "r");
var_dump($http_response_header);
gives:
<b>Warning</b>: fopen("http://yahoo.com/","r") - Success in
<b>/tmp/fopen.php</b> on line <b>4</b><br>
array(2) {
[0]=>
string(15) "HTTP/1.0 302 RD"
[1]=>
string(31) "Location: http://www.yahoo.com/"
}
So I think that whenever we get a report with fopen and Success, we
should ask for contents of $http_response_header.
I think perhaps it's okay to let the user check the array, and do another
fopen, but I think it might be less work for both us and the users that
we automatically follow the redirect.
But before I do that, was there a good reason for removing the redirect
handling?
> Your comment about a redirect got me thinking.
>
> I tried the url that was posted in the bug report
> (http://ir.stockmaster.com/c/pbn/stocks.html) - and I did get
> an error message. This is may be because the client gets routed
> to a different location -
> http://ir1.stockmaster.com/c/pbn/stocks.html
Right, good point! Mike, could you try to do
var_dump($http_response_header);
right after the fopen?
Stig