473,378 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Read a website with Fopen()

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.

<?php
$file="http://www.radios.pt/portalradio/";
$fp = fopen($file, "r");
while (!feof($fp))
{
$a=$a.fgets($fp);
}
fclose($fp);
echo $a;
?>

Nov 30 '07 #1
6 6421
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 = 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 <pro.ra...@hotmail.comwrote:
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.

<?php
$file="http://www.radios.pt/portalradio/";
$fp = fopen($file, "r");
while (!feof($fp))
{
$a=$a.fgets($fp);}

fclose($fp);
echo $a;
?>
Nov 30 '07 #2
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.

<?php
$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.
js*******@attglobal.net
==================

Nov 30 '07 #3
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.

<?php
$file="http://www.radios.pt/portalradio/";
$fp = fopen($file, "r");
while (!feof($fp))
{
$a=$a.fgets($fp);
}
fclose($fp);
echo $a;
?>
Use curl.
Nov 30 '07 #4
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.
Nov 30 '07 #5
On Fri, 30 Nov 2007 14:01:24 +0100, Jonas Werres <jo***@example.orgwrote:
>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
Nov 30 '07 #6
$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 .
<comp.lang.php>
<zenner>
<Fri, 30 Nov 2007 03:01:58 -0800 (PST)>
<bc**********************************@y5g2000hsf.g ooglegroups.com>
Below is an example of a site that gives an error when you try to read
it.

<?php
$file="http://www.radios.pt/portalradio/";
$fp = fopen($file, "r");
while (!feof($fp))
{
$a=$a.fgets($fp);
}
fclose($fp);
echo $a;
?>
Dec 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: typingcat | last post by:
Is it possible to read another web page in PHP? If is ASP.NET, the code would be ------------ WebRequest req=WebRequest.Create("http://www.microsoft.com"); WebResponse res=req.GetResponse();...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
6
by: Patrice Kadionik | last post by:
Hi all, I want to make a brief comparison between read() and fread() (under a Linux OS). 1. Family read and Co: open, close, read, write, ioctl... 2. Family fread and Co: fopen, fclose,...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
9
by: fazulu deen | last post by:
Hi all, I have to read two text file(opcode,jump)... I guess the following statements are correct(but it is not reading the data from that files and also not checking the presence of the...
23
by: asit dhal | last post by:
hello friends, can anyone explain me how to use read() write() function in C. and also how to read a file from disk and show it on the monitor using onlu read(), write() function ??????
4
Mague
by: Mague | last post by:
I have got a website with a few friends from school(year8). We have got a website up. I want it so it looks for a textfile and reads and writes it into a textbox. It does do this. The only problem is...
5
by: chazzy69 | last post by:
The error : http://www.somesite.com Warning: fopen() : php_network_getaddresses: getaddrinfo failed: Name or service not known in /etc/etc/etc/etc/test.php on line 766 Warning:...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.