Read a website with Fopen()
Read a website with Fopen()
am 30.11.2007 12:01:58 von zenner
Hello.
when i try to "read" some websites with fopen() some of them allow but
some don't
Does the server knows that it=B4s not a web browser that it's trying to
access?
How can i solve this??
Below is an example of a site that gives an error when you try to read
it.
$file=3D"http://www.radios.pt/portalradio/";
$fp =3D fopen($file, "r");
while (!feof($fp))
{
$a=3D$a.fgets($fp);
}
fclose($fp);
echo $a;
?>
Re: Read a website with Fopen()
am 30.11.2007 12:31:15 von petersprc
Hi,
You can adjust the User-Agent header like so:
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.10) Gecko/20071115 Firefox/2.0.0.10');
Then fetch a page:
$doc =3D file_get_contents('http://example.net');
If you want to implement a mirror, you can use mod_proxy and
mod_proxy_html. For example:
ProxyPass /my/mirror/ http://example.net/
If you want to store locally a page and associated images and scripts,
you can use wget with the -p option:
wget -p http://example.net
On Nov 30, 6:01 am, zenner wrote:
> Hello.
> when i try to "read" some websites with fopen() some of them allow but
> some don't
> Does the server knows that it=B4s not a web browser that it's trying to
> access?
> How can i solve this??
>
> Below is an example of a site that gives an error when you try to read
> it.
>
>
> $file=3D"http://www.radios.pt/portalradio/";
> $fp =3D fopen($file, "r");
> while (!feof($fp))
> {
> $a=3D$a.fgets($fp);}
>
> fclose($fp);
> echo $a;
> ?>
Re: Read a website with Fopen()
am 30.11.2007 13:33:15 von Jerry Stuckle
zenner wrote:
> Hello.
> when i try to "read" some websites with fopen() some of them allow but
> some don't
> Does the server knows that it´s not a web browser that it's trying to
> access?
> How can i solve this??
>
> Below is an example of a site that gives an error when you try to read
> it.
>
>
> $file="http://www.radios.pt/portalradio/";
> $fp = fopen($file, "r");
> while (!feof($fp))
> {
> $a=$a.fgets($fp);
> }
> fclose($fp);
> echo $a;
> ?>
>
>
They could be checking the headers for the user agent. Like anything
sent by the client, however, it's not very reliable.
Usually when they do such things it's because they don't want people
accessing their site from scripts.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Read a website with Fopen()
am 30.11.2007 13:57:32 von taps128
zenner wrote:
> Hello.
> when i try to "read" some websites with fopen() some of them allow but
> some don't
> Does the server knows that it´s not a web browser that it's trying to
> access?
> How can i solve this??
>
> Below is an example of a site that gives an error when you try to read
> it.
>
>
> $file="http://www.radios.pt/portalradio/";
> $fp = fopen($file, "r");
> while (!feof($fp))
> {
> $a=$a.fgets($fp);
> }
> fclose($fp);
> echo $a;
> ?>
>
Use curl.
Re: Read a website with Fopen()
am 30.11.2007 14:01:24 von Jonas Werres
> Read a website with Fopen()
You don't want to do that as it will not work in a sane php setup
(allow_url_fopen should be disabled).
Use fsockopen and the HTTP Protocol manually or use a class like Pears HTTP.
Re: Read a website with Fopen()
am 30.11.2007 15:41:49 von luiheidsgoeroe
On Fri, 30 Nov 2007 14:01:24 +0100, Jonas Werres wrote:
>> Read a website with Fopen()
>
> You don't want to do that as it will not work in a sane php setup
> (allow_url_fopen should be disabled).
Curious: why should it be?
--
Rik Wasmus
Re: Read a website with Fopen()
am 02.12.2007 12:29:09 von Hans-Peter Sauer
$handle = fopen("http://www.radios.pt/portalradio/", "rb");
$contents = '';
while (!feof($handle))
{$contents .= fread($handle, 8192);}
fclose($handle);
$filename="content.txt"; $fp=fopen($filename,"w"); fwrite ($fp,
$contents); fclose($fp);
I havent tried the above - its just a code snippet i have .
> Below is an example of a site that gives an error when you try to read
> it.
>
>
> $file="http://www.radios.pt/portalradio/";
> $fp = fopen($file, "r");
> while (!feof($fp))
> {
> $a=$a.fgets($fp);
> }
> fclose($fp);
> echo $a;
> ?>
>