472,954 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

fopen() unable to open some URLs?

Hi,

I've used fopen() extensively to open web pages. I've found that there is a
small minority
of web pages that open fine in a browser, but are inaccessible using
fopen(). Here are
two such URLs:

http://www.homes.com/
http://www.dolbyproperties.com/

For example, using the code below, almost every web page that will open in a
browser
will be read correctly by this code. There are few exceptions, such as the
above URLs.
I'm wondering why/how could a page be accessible to a browser but not to
fopen()?

Here's the code:

<?php

$page = "";

if (isset($url))
{
$fp = fopen($url, 'r');

if ($fp != false)
{
while (feof($fp) == false)
{
$page .= fread($fp, 10000);
}

fclose($fp);

echo "URL: $url =====================================<br><br>";
echo $page;
}
}

?>

I have this code running with a simple form interface here:

http://linkmachine.net/fopen_test.php

Any ideas?

Thank you,

-Michael


Aug 11 '05 #1
1 2322
Michael Ferrier wrote:
For example, using the code below, almost every web page that will
open in a browser
will be read correctly by this code. There are few exceptions, such
as the above URLs.
I'm wondering why/how could a page be accessible to a browser but not
to fopen()?


Some websites require an explicit user-agent header in order to return a
response, as is the case with homes.com

There are several ways to include the user agent, of which the easiest is to
apply the ini_set function as follows:

ini_set('user_agent','Mozilla');
$fp = fopen('http://www.homes.com/','r');
fpassthru($fp);

When you run this code, you will see it works fine for homes.com. Bare in
mind that this doesn't work for sites which require more then a user agent
string to operate.

JW

Aug 11 '05 #2

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

Similar topics

5
by: Shaoyong Wang | last post by:
Dear All, I want to write a simple PHP code to verify whether a given list of URLs is broken or not. The URLs given have various formats, for example, http://www.afro.com/history/history.html...
3
by: Ming | last post by:
When I use fopen on the URL: fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r") I would get the following error message: -----------Error Message------------ Warning: fopen():...
10
by: Longfellow | last post by:
Newbie here... My reading of the description of fopen() led me to expect that, with mode as "w", it would create a file if it did not exist. Checked the FAQ and did not see this question...
5
by: eyalc1978 | last post by:
Hi Does someone knows if fopen() is a non-blocking function in a sense that if there isn't sufficient disk space to open a file in write mode, then the function will not wait but fail? I find...
4
by: lucyachammond | last post by:
I have a 3rd party real-estate website written in php. I would like to call an asp script on a separate webserver each time a new real-estate item is added to the database on the php site. The...
1
by: nebelraabe | last post by:
hi there. I encountered a problem when i wanted to open a file which name i read from an ini file. FILE *fopen(const char *filename, const char *mode); as far as i know, fopen( ) accepts only...
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
3
by: mrmattborja | last post by:
Hello, Here is a program I'm playing around with for fun in the process of learning C. The objective is to create a function filesize() and call it from within the main() section to retrieve the...
6
by: chazzy69 | last post by:
So the function fopen() works most of the time heres the line im using- $file = fopen($nextPage, "r") or exit("Unable to open file!"); But for some reason that i haven't been able to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.