Re: fopen()
| From: | Chris Knipe | Date: | Sat, 20 Jul 2002 00:38:34 +0000 |
| Subject: | Re: fopen() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108607@lists.php.net to get a copy of this message | ||
> > if (!($fc =
> >
> > fopen("http://www.google.com/search?hl=en&&ie=ISO-8859-1q=asd
> > f", "r"))) {
> > echo "couldnt open file.";
> > } else {
> > $content = fread($fc,10000000);
> > }
> > echo "$content\n";
> >
> > Why doesn't this work?
>
> What happens if you just type:
>
> http://www.google.com/search?hl=en&&ie=ISO-8859-1q=asdf
>
> Into a web browser? Does it load what you expected to load?
Yes. It does. And to make it even more bizarre, when I use fsockopen and
fgets I get the page back!
However, there are also instances where fsockopen and fgets do not return
the page either... Some other instances, fgets prints a 301 / 302 redirect
message as the output.
What I am starting to think, is that google often returns 301 / 302 error
codes (Object has moved). Does fopen and fsockopen follow 30* redirect
requests? Even a better question, does fopen() return error text if it gets
a error code from the server?
--
me
PS: Here's the fsockopen code that works (on a temporary basis)
$google = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$google) {
echo "Can't connect\n";
} else {
fputs($google, "GET /search?hl=en&&ie=ISO-8859-1q=asdf\r\n\r\n");
while (!feof($google)) {
echo fgets($google, 128);
}
close($google);
}